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 Build a Playlist Browser with Swift Working With Multiple View Controllers Segues

swift thread 1: exc_bad_instruction(code=exc_i386_invop,subcode=0x0) error

In my a view controller where I changed the class to "PlaylistMasterViewController" I'm getting an error on the line where I have the code "aButton.setTitle("Press me!",forState: .Normal)".

The error says "swift thread 1: exc_bad_instruction(code=exc_i386_invop,subcode=0x0)" When I comment it out it work fine. From reading the error it appears that it is an optional and upwrapping it with a bang(!) is producing an error because there is not value there. When I look into Pasan's code, it works. Any idea what could be wrong?


import UIKit

class PlaylistMasterViewController: UIViewController {

    @IBOutlet weak var aButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()

        aButton.setTitle("Press me!",forState: .Normal)
    }

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


}

4 Answers

Not sure if you ever got the reply to this question but based on my experience every time you get that sort of errors is because "something is missing" compared to what is in your view controller. In this case, if you renamed things is probably that somewhere in your code something is referring to previous name of what was changed.

I came across same error myself some times and most recent one was because I was missing a LABEL that used to exist and I replaced it by mistake.

Thanks Ricardo,

This was a though one. I have it in my github. I was trying to make a side by side comparison and everything seemed the same and I couldn't find the error. At the end, I ended up copying the project so that I can continue with the lesson. Thank you for trying to help.

Regards, Philip

I totally understand Phillip, I've been there before with the exact same error and in the exact same scenario where I was comparing a code that runs VS mine (which didn't run at that time) and it was the exact same code so the difference is not actually in the actual code on the swift file but it was on a missing item/component as like the ones showed here: http://bit.ly/1zFVJQG

PS: in my case I had deleted a LABEL so code was right and 100% identical to another that run fine is just that label didn't exist.

Interesting, my suspicion was that I mislabeled something in the custom classes. I'll take another look at my labels. I was able to move forward and incorporate the images, I'd just like to know what went wrong.

I had exactly the same problem, and ended up deleting the whole project and recreating it. Having done that, my suspicion is that the problem was caused by deleting the aButton outlet reference when I was deleting the action - this may be your problem too?

It's so frustrating trying to debug issues in new languages :)

Thats funny that you say that. My initial code was not responding to the the first time we used the "aButton" to set the normal state "Press me!" to "button pressed." I looked up and down and couldn't figure it out. I think the error came from the change in the aButton.

In my Main.storyboard file, when I compare the one I made with Pasan's, mine has no referencing outlet for the button.

To correct. Ctrl drag button onto the PlaylistMasterViewController.swift file right under the @IBOutlet weak var aButton: UIButton! code that is already there. then delete the old @IBOutlet weak var aButton: UIButton! text AND click the circle in the gutter and delete the old one there too.

You will see the button has a new outlet reference in the connections inspector I ran it again -> no errors.