致命错误:init(coder:) 尚未实现 Xcode 7 iOS 9
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32696980/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
fatal error: init(coder:) has not been implemented Xcode 7 iOS 9
提问by icekomo
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.
我昨晚更新了一个 Xcode 6 / iOS 8 项目,似乎遇到了一些问题。其中之一是它会抛出一条致命的错误消息并使应用程序崩溃。当按下按钮时,我正在尝试设置下一个。
let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("gameViewController")
self.presentViewController(viewController, animated: true, completion: nil)
Then inside the gameViewController I have this:
然后在 gameViewController 里面我有这个:
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.
在我更新到所有内容的最新版本之前,这一切似乎都运行良好,但我不确定发生了什么变化。
回答by matt
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.
请注意第一行中的问号和最后一行中缺少感叹号。