Converting String to Int with Swift

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)

Leave a Comment