线程1:exc_bad_instruction code = exc_i386_invop,subcode = 0x0 - Swift3

时间:2017-01-04 22:20:11

标签: swift

我在尝试运行一个简单的应用程序时遇到错误,该应用程序验证输入的值是素数#:

主题1:exc_bad_instruction代码= exc_i386_invop,子代码= 0x0

    @IBAction func isItPrime(_ sender: AnyObject) {

    if let userEnteredString = numberTextField.text {

        let userEnteredInteger = Int(userEnteredString)

        if let number = userEnteredInteger {

            var isPrime = true

            if number == 1 {

                isPrime = false
            }

            var i = 2

            while i  < number {

                if  number % i == 0 {

                    isPrime = false
                }

                i += 1

            }
            if isPrime {

                result.text = "\(number) is prime!"
            }
            else {
                result.text = "\(number) is not prime"
            }


        } else {

            result.text = "Please enter a positiive whole number"
        }

    }
}

它显示了行号(数字)下的错误:

     result.text = "\(number) is not prime"

控制台显示:

2017-01-04 13:04:28.124865 Is it Prime[15609:882259] subsystem: com.apple.siri, category: Networking.Performance, enable_level: 3, persist_level: 2, default_ttl: 0, info_ttl: 0, debug_ttl: 0, generate_symptoms: 1, enable_oversize: 0, privacy_setting: 0, enable_private_data: 0 fatal error: unexpectedly found nil while unwrapping an Optional value

0 个答案:

没有答案