【发布时间】:2015-06-30 05:50:37
【问题描述】:
以下错误:无法使用类型为 '(@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 时会出错,以及如何解决这个问题并让它像我想要的那样运行。非常感谢所有答案
【问题讨论】: