我得到這個錯誤:錯誤「Thread 1:EXC_BAD_INSTRUCTION(code = EXC_I386_INVOP,subcode = 0x0)」是什麼意思?
Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
我該如何解決這個問題?該代碼正常工作,但在計算器中,當我點擊唯一的平等按鈕時,會出現該錯誤。
@IBAction func equals(sender: AnyObject) {
secondNumber = Screen.text!.toInt()! // here it shows an error which is "Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)"
if operation == "+"{
result = firstNumber + secondNumber
}
else if operation == "-" {
result = firstNumber - secondNumber
}
else if operation == "x" {
result = firstNumber * secondNumber
}
else {
result = firstNumber/secondNumber
}
Screen.text = "\(result)"
}
在這行'result = firstNumber/secondNumber''secondNumber'等於零時會發生什麼? – 2015-03-02 07:50:15
是的,我知道它是未定義的,所以我如何解決它? 「 – legolas 2015-03-02 07:53:39
」將數字除以零('i/0'),或試圖通過零計算餘數('i%0'),將導致錯誤。「 - [Swift編程語言 - 高級操作符](https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AdvancedOperators.html) – 2015-03-02 07:55:59