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

安稳与你 提交于 2019-12-23 16:21:14

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/32696980/fatal-error-initcoder-has-not-been-implemented-xcode-7-ios-9

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!