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.

3
  • You posted an initialiser from gameViewController and the warning is about GameOptionsViewController. Are you sure that you are looking at the right file? Commented Sep 21, 2015 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 Commented Sep 21, 2015 at 19:01
  • Yes I upgraded using swift, but it didn't fix this for me.... odd Commented Sep 21, 2015 at 23:14

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

What does the "?" do in this function instance?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.