1 Reply
      Latest reply: Feb 19, 2017 1:50 PM by eskimo RSS
      App_Developer Level 1 Level 1 (0 points)

        Ive been getting this error and have no idea what it means, any advice is welcomed.

         

        import UIKit

        class ViewController: UIViewController {

         

         

            var numberOnScreen:Int = 0;

            var converted = " ";

            var convert = 0;

         

            @IBOutlet weak var label: UILabel!

         

            @IBAction func numberInput(_ sender: UIButton)

            {

                label.text = label.text! + String(sender.tag-1)

                if numberOnScreen == 0

                {

                    numberOnScreen = 0

                }

                else

                {

                    numberOnScreen = Int(label.text!)!

                }

            

            }

         

            @IBAction func extraButtons(_ sender: UIButton)

            {

                if sender.tag == 12

                {

                    convert = Int(label.text!)!                             (Error is here)

                    converted = String(convert, radix:2)

                    label.text = String(converted)

                }

                else if sender.tag == 11

                {

                    numberOnScreen = 0;

                    convert = 0;

                    converted = String(0);

                    label.text = " ";

                }

            }

         

            override func viewDidLoad() {

                super.viewDidLoad()

                /

            }

            override func didReceiveMemoryWarning() {

                super.didReceiveMemoryWarning()

                /

            }

        }

         

         

         

         

        Thanks again in advance!

        • Re: exc_bad_instruction(code=exc_i386_invop,subcode=0x0)
          eskimo Apple Staff Apple Staff (6,995 points)

          You should start by reading my explanation for what EXC_BAD_INSTRUCTION means.

          You’ve got three potential causes of this on the line you quoted:

          • label is nil (note there’s no exclamation mark for label because it’s implicitly unwrapped)

          • label.text is nil

          • label.text can’t be converted to an Int

          You may be able to tease them apart in the debugger but, if you not, tease them apart in code.  For example:

          let l = label
          let t = l.text!
          convert = Int(t)!
          

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"