一元运算符' - '不能应用于'@lvalue Int'类型的操作数

时间:2017-10-20 09:23:53

标签: iphone swift

@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()
}

1 个答案:

答案 0 :(得分:6)

您应该使用score = score + 1代替score++