元运算符“ - ”不能应用于类型的操作数“@lvalue INT”
问题描述:
@IBAction func blueBtnAct(_ sender: AnyObject) {
score++ //error bcause Unary operator '++' cannot be applied to an operand of type '@lvalue Int'
blueLbl.text = "\(score)"
GrenLbl.text = "\(score)"
testScore()
}
@IBAction func GrenBtnAct(_ sender: AnyObject) {
score-- //error bcause Unary operator '--' cannot be applied to an operand of type '@lvalue Int'
blueLbl.text = "\(score)"
GrenLbl.text = "\(score)"
testScore()
}
答
您应该使用的,而不是score++
的推荐替代使用
score = score + 1
是'得分+ = 1' – vadian是你right @vadian但是score = score + 1易于学习 – Zee
不,学习正确的东西。谁能理解'++'也会理解'+ = 1' ;-) – vadian