Error using Swift - Instance member cannot be used on type 'ViewController'

前端 未结 2 2022
野趣味
野趣味 2020-12-09 20:08

I\'ve been trying to make an app in Xcode 7 using Swift and I\'m trying to convert numbers inside a textfield to an integer using this code, let a = Int(percentLabel.t

2条回答
  •  佛祖请我去吃肉
    2020-12-09 20:45

    This code returns a new value every time you call it. I expect it what you're looking for

    var myInt: Int? {
        return Int(percentLabel.text!)
    }
    

    instead of

    let myString = percentLabel
    let myInt: Int? = Int(myString)
    

提交回复
热议问题