Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

I am getting an error in Xcode 8.

Hi, I am just trying to display text obtained from a textbox and display it another view controller in a label. All the view controllers are linked to one code page. But for reason I am getting an error as follows: Thread 1:EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0).

import UIKit
class ViewController: UIViewController {

    @IBOutlet weak var nameTextBox: UITextField!

    @IBOutlet weak var firstQuestion: UILabel!

    @IBAction func nextButton() {
        if nameTextBox.text != nil {
            let name = nameTextBox.text
            firstQuestion.text = name
        }
        else {
            print("Wrong!")
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}

Thank you in advance for your help.

2 Answers

Please can someone reply.

Ronav, the code here looks solid. I would check to make sure all of the outlets are set up as you want them just to make sure. If you have any questions, feel free to ask!

Hi, Everything seems fine but when I enter my name in the textbox it is supposed to display in a label in another view controller which is linked to the same code page. However Xcode 8 highlights: firstQuestion.text = name, and gives the following error. 'Thread 1: EXC_BAD_INSTRUCTION (code=EXC_1386_INVOP, subcode=0x0). Thank you for helping me and I am looking towards your valuable suggestions. Ron.

In the Xcode 8 console it says: fatal error: unexpectedly found nil while unwrapping an Optional value.