gpt4 book ai didi

ios - 随机数语句不适用于我的 toInt 文本字段输入

转载 作者:行者123 更新时间:2023-11-28 09:04:43 24 4
gpt4 key购买 nike

以下错误:无法使用类型为“(@lvalue Int?, @lvalue UInt32)”的参数列表调用“==”

@IBOutlet weak var textBox: UITextField!

@IBOutlet weak var result: UILabel!

@IBAction func submit(sender: AnyObject) {
var randomNumber = arc4random_uniform(4)+1//look at the first if declaration. This is were my question is
var guess = textBox.text.toInt()
if guess == randomNumber { //error: Cannot invoke '==' with an argument list of type '(@lvalue Int?, @lvalue UInt32)
guess.text = "Well done, correct!"
}
else if guess < 0 {
guess.text = "WHAT!?!? that wasn't even an option"
}
else if guess > 5 {
guess.text = "WHAT!?!? that wasn't even an option"
}
else {
guess.text = "WRONG the correct answer was \(randomNumber)"
}

请告诉我为什么在 arcforrandom 中使用 == 会出错,以及我如何解决这个问题并让它按我想要的方式运行。非常感谢所有答案

最佳答案

Uint 转换为 Int

var randomNumber = Int( arc4random_uniform(4)+1 )

和..

为什么 guess.text 你的意思是 result.text

关于ios - 随机数语句不适用于我的 toInt 文本字段输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31130534/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com