3

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.

Tejas Ardeshna
  • 4,343
  • 2
  • 20
  • 39
icekomo
  • 9,328
  • 7
  • 31
  • 59
  • You posted an initialiser from `gameViewController` and the warning is about `GameOptionsViewController`. Are you sure that you are looking at the right file? – Adam Sep 21 '15 at 14:35
  • converting your project from Swift 1.2 to swift 2.0 should solve this automatically. Did you convert your project with xcode? The answer matt gave you is correct btw! [Start converter Swift 1.2 to 2.0](http://stackoverflow.com/questions/32692935/re-open-the-review-and-converter-to-swift-2-0-xcode-7) – Gerrit Post Sep 21 '15 at 19:01
  • Yes I upgraded using swift, but it didn't fix this for me.... odd – icekomo Sep 21 '15 at 23:14

1 Answers1

8

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141