Ilker Baltaci
Ilker Baltaci

Reputation: 11789

iOS App Crashes in didFinishLaunchingWithOptions due to IBOutlet

In my iOS App I have an initial viewcontroller with 2 textfields for login. If i run the application in debug mode code compiles good and i can see the initial viewcontroller that i set on my main storyboard.

In opposite if i try to run the code in Release the app crashes calming that the outlet are not set.

2017-04-07 13:55:53.422 Sahin Fruit[40068:1230157] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fb5e2e0a450> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key emailTextField.'

To overcome the problem i tries to set the initial VC in AppDelegate programatically but no result, the app still crashes. Any idea?

    self.window = UIWindow(frame: UIScreen.main.bounds)
    let initialViewController = UIStoryboard.viewControllerWithIdentifier(Main.loginVC.rawValue, storyBoardName: .Main)
    self.window?.rootViewController = initialViewController
    self.window?.makeKeyAndVisible()

P.S: I turned off the optimisation in Release to see if that would help also no result.

Upvotes: 1

Views: 377

Answers (3)

Satish Babariya
Satish Babariya

Reputation: 3096

Check your references of your outlets in your Storyboard, one of them is probably referencing a property that does not exist anymore

Upvotes: 0

Kunal Kumar
Kunal Kumar

Reputation: 1722

This is because you must have copied the ViewController in storyboard and assigned it different class. Just right click on the top of ViewController at the first square box(Forgot the exact name), and your extra outlet ll be shown with yellow color triangle, just delete it and your project will build fine.

enter image description here

Upvotes: 1

hamdi islam
hamdi islam

Reputation: 1521

You have an old outlet that you deleted from code but still connected in the interface builder

Upvotes: 0

Related Questions