-2
所以我一直想輸入數字的這個字符串轉換成變量,但出於某種原因,每一個可能的組合,我嘗試,它總是給我一個錯誤雨燕2.0字符串到整數
@IBOutlet weak var age: UITextField!
@IBOutlet weak var finalYears: UILabel!
@IBAction func findYears(sender: AnyObject) {
var enteredYears = age.text.toInt()
if enteredYears != nil {
var catYears = enteredYears * 7
finalYears.text = "Your cat is \(catYears)"
} else {
finalYears.text = "Please enter another number"
}
}
而對於一些原因就行了
var enteredYears = age.text.toInt()
我似乎總是與這段代碼