简体   繁体   English

Int无法转换为UIint32错误

[英]Int is not convertible to UIint32 error

i am new to swift and Xcode and i need some help. 我是Swift和Xcode的新手,我需要一些帮助。 I have a function that gets to integer variables. 我有一个获取整数变量的函数。 And when i use them they give me errors. 当我使用它们时,它们给了我错误。 here is the code 这是代码

func checkTheNumber(range: Int, numberOfGuesses: Int) { var randomNumber = Int(arc4random_uniform(range) + 1) numberOfGuesses-- when i try to use the range variable it says "Int is not convertible to UIint32" and when i try to use number of guesses it says "unary operator cannot be applied to an operand of type Int" func checkTheNumber(range: Int, numberOfGuesses: Int) { var randomNumber = Int(arc4random_uniform(range) + 1) numberOfGuesses--当我尝试使用范围变量时,它说“ Int无法转换为UIint32”,当我尝试使用表示“无法将一元运算符应用于Int类型的操作数”的猜测数目

Change it with : 用:

 var randomNumber = Int(arc4random_uniform(UInt32(range)) + 1)

You have to cast the Int to UIint32 您必须将Int UIint32UIint32

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM