cannot convert value of type 'UILabel!' to expected argument 'type inout String'

前端 未结 1 1171
忘掉有多难
忘掉有多难 2021-01-23 01:31

When I try to increase currentNumberAdmin I get:

cannot convert value of type \'UILabel!\' to expected argument \'type in out String\'

<
1条回答
  •  执念已碎
    2021-01-23 02:31

    This is crashing because of this line: currentNumberAdmin += String(1). You're attempting to add a String value to a UILabel value, which is invalid. You're literally telling the compiler to assign currentNumberAdmin, a UILabel, to the value of the expression of adding a UILabel to a String, which the compiler doesn't know how to do, hence the exception message.

    It's not entirely clear why you're attempt to set the label's text twice: once with snapshot.value, and then again on the next line. If what you're trying to do is set the label's text to the snapshot value + 1, do something like this:

    @IBAction func nextCurrent(_ sender: UIButton) {
        let database = FIRDatabase.database().reference()
        database.child("current").observe(FIRDataEventType.value, with: { (snapshot) in
    
          var strVal = Int(self.currentNumberAdmin.text)!
          strVal += 1
          self.currentNumberAdmin.text = String(strVal)
        })
    
    }
    

    0 讨论(0)
提交回复
热议问题