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)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…