Converting String to Int with Swift

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

    Because a string might contain non-numerical characters you should use a guard to protect the operation. Example:

    guard let labelInt:Int = Int(labelString) else {
        return
    }
    
    useLabelInt()
    

提交回复
热议问题