icekomo
icekomo

Reputation: 9466

fatal error: init(coder:) has not been implemented Xcode 7 iOS 9

I updated an Xcode 6 / iOS 8 project last night and seem to have ran into a few issues. One of them being is it's throwing a fatal error message and crashing the app. When a button is pressed I'm trying to set up the next.

let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("gameViewController") 
self.presentViewController(viewController, animated: true, completion: nil)

Then inside the gameViewController I have this:

required init(coder aDecoder: NSCoder) {
    // SWIFT 2 update
    state = .OptionsVisible
    super.init(coder: aDecoder)!
    //fatalError("init(coder:) has not been implemented")
}

This seems to be where the fatal error is being thrown as the error message is the following:

fatal error: init(coder:) has not been implemented: file /pathToApp/GameOptionsViewController.swift, line 81

This all seemed to work fine before I updated to the newest versions of everything, and I'm not really sure what changed.

Upvotes: 3

Views: 6561

Answers (1)

matt
matt

Reputation: 535304

Rewrite like this:

required init?(coder aDecoder: NSCoder) {
    state = .OptionsVisible
    super.init(coder: aDecoder)
}

Notice the question mark in the first line and the lack of exclamation mark in the last line.

Upvotes: 8

Related Questions