Converting String to Int with Swift

前端 未结 30 1587
小鲜肉
小鲜肉 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:26

    Updated answer for Swift 2.0+:

    toInt() method gives an error, as it was removed from String in Swift 2.x. Instead, the Int type now has an initializer that accepts a String:

    let a: Int? = Int(firstTextField.text)
    let b: Int? = Int(secondTextField.text)
    

提交回复
热议问题