.toInt() removed in Swift 2?

Solution 1:

In Swift 2.x, the .toInt() function was removed from String. In replacement, Int now has an initializer that accepts a String

Int(myString)

In your case, you could use Int(textField.text!) insted of textField.text!.toInt()

Swift 1.x

let myString: String = "256"
let myInt: Int? = myString.toInt()

Swift 2.x, 3.x

let myString: String = "256"
let myInt: Int? = Int(myString)

Solution 2:

Swift 2

let myString: NSString = "123"
let myStringToInt: Int = Int(myString.intValue)

declare your string as an object NSString and use the intValue getter

Solution 3:

Its easy enough to create your own extension method to put this back in:

extension String {
    func toInt() -> Int? {
        return Int(self)
    }
}