Converting String to Int with Swift

前端 未结 30 1613
小鲜肉
小鲜肉 2020-11-22 06:59

The application basically calculates acceleration by inputting Initial and final velocity and time and then use a formula to calculate acceleration. However, since the value

30条回答
  •  别那么骄傲
    2020-11-22 07:01

    myString.toInt() - convert the string value into int .

    Swift 3.x

    If you have an integer hiding inside a string, you can convertby using the integer's constructor, like this:

    let myInt = Int(textField.text)
    

    As with other data types (Float and Double) you can also convert by using NSString:

    let myString = "556"
    let myInt = (myString as NSString).integerValue
    

提交回复
热议问题