DannieCoderBoi
DannieCoderBoi

Reputation: 728

Swift: exc_breakpoint (code=exc_arm_breakpoint subcode=0xdefe) on prepareForSegue

For some reason I am getting this error when the performSegueWithIdentifier line is reached.

I have this code:

if let storedAPIKeychain: AnyObject = dictionary.objectForKey("api_key") {

            println(storedAPIKeychain)

            //This is the line that causes the problems. 
            performSegueWithIdentifier("skipBrandSegue", sender: self)

        }

The println() works fine and outputs the correct information.

I am trying to pass the storedAPIKeychain along with the segue:

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
    if segue.identifier == "skipBrandSegue" {

        // Create a new variable to store the instance of the next view controller
        let destinationVC = segue.destinationViewController as brandsViewController
        destinationVC.storedAPIKey = storedAPIKeychain!

     }
}

Which I thought might have been the problem. however when I changed that line to:

destinationVC.storedAPIKey = "someAPIplaceholder"

I also get the same error.

Can someone please advise me what this error is and how to resolve it. Thanks.

Edit: Screenshot of error: Xcode DebugError

Upvotes: 3

Views: 5912

Answers (2)

MarkP
MarkP

Reputation: 2566

@antonios answer should solve your problem. The break is due to the object not being cast (found and assigned).

Just a side note: you're going to have a few issues with this line:

if let storedAPIKeychain: AnyObject = dictionary.objectForKey("api_key")

especially if you're expecting to get a String from it and pass that between ViewControllers?

Cast it as a String, Create a global scope variable and then assign it to that variable to use - Will be much easier to handle then.

var globalVariable = "" //add this line at the top, just before your class declaration. 

if let storedAPIKeychain = dictionary.objectForKey("api_key") as? String {
    self.globalVariable = storedAPIKeychain
}

Upvotes: 4

Antonio
Antonio

Reputation: 72790

The dynamic cast class unconditional indicates that a forced cast failed, because a variable cannot be cast to another type.

In your code I see one cast only at this line:

let destinationVC = segue.destinationViewController as brandsViewController

which means the destination view controller is not an instance of brandsViewController.

To fix the issue:

  • check in interface builder that the custom class property for the destination view controller is correctly set to brandsViewController
  • check that the segue is actually pointing to that view controller

If none of the above fixes the problem, set a breakpoint at that line and inspect the actual type of the destination view controller.

Side note: by convention, in swift all type names start with uppercase letter, whereas functions, variables and properties with lower case. If you want to make your code readable to other swift developers, I suggest you to stick with that convention (rename brandsViewController as BrandsViewController)

Upvotes: 4

Related Questions