I was working on an application that used a text field and translated it into an integer. Previously my code
textField.text.toInt()
worked. Now Swift declares this as an error and is telling me to do
textField.text!.toInt()
and it says there is no toInt()
and to try using Int()
. That doesn't work either. What just happened?
In Swift 2.x, the
.toInt()
function was removed fromString
. In replacement,Int
now has an initializer that accepts aString
In your case, you could use
Int(textField.text!)
insted oftextField.text!.toInt()
Swift 1.x
Swift 2.x, 3.x