Julian Pomper Julian Pomper - 4 months ago 10
iOS Question

Why my app crashes with fatal error, but only on first launch?

When I launch my app, and click the button, the app crashes with

fatal error: unexpectedly found nil while unwrapping an Optional value
, but when I start the simulator again, everything is fine when I click it.

This is the code the button executes:

func showProfile(sender:AnyObject?){
let profile = App.mainStoryboard.instantiateViewControllerWithIdentifier("profile") as! Profile

//Here is the error
animateToView(self.navigationController!, view: profile, midX: self.profileItem.frame.midX, midY: self.profileItem.frame.midY)
}

Answer

I think the problem is with your navigationController

if let _ = self.navigationController {
    animateToView(self.navigationController!, view: profile, midX: self.profileItem.frame.midX, midY: self.profileItem.frame.midY)
}