我想创建一个if else语句。如果randomNumber等于标签的文本,那么我想给CorrectLabel
加1。如果它们不相等,则表示我想将IncorrectLabel
加1。这里是我的代码:运算符'!='的模糊使用?
@IBAction func checkButton(sender: UIButton) {
if ("\(randomImageGeneratorNumber)" == "\(currentCountLabel.text)"){
currectAmountCorrect += 1
CorrectLabel.text = "\(currectAmountCorrect)"
}else if ("\(randomImageGeneratorNumber)" != "\(currentCountLabel.text)"){
currentAmountIncorrect += 1
IncorrectLabel.text = "\(currentAmountIncorrect)"
}
}
我对“否则,如果”语句行得到一个错误说“不明确的使用操作符‘!=’”。我不确定这个错误的含义或如何解决。
这个错误是什么意思,它是如何解决的?
如果双方(左和右)都是字符串,那么这个问题已经被固定在雨燕1.2(刚试过它)。与此同时,你可以用'if(lhs == rhs)'来代替(或者只是一个'else',因为你的第一个标准只是一个平等测试,因此暗含不等式) – Alladinian 2015-03-08 21:05:23