【问题标题】:fatal error: init(coder:) has not been implemented Xcode 7 iOS 9致命错误:init(coder:) 尚未实现 Xcode 7 iOS 9
【发布时间】:2015-09-21 13:48:58
【问题描述】:

我昨晚更新了一个 Xcode 6 / iOS 8 项目,似乎遇到了一些问题。其中之一是它会引发致命错误消息并使应用程序崩溃。当按下一个按钮时,我正在尝试设置下一个。

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

然后在 gameViewController 我有这个:

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

这似乎是引发致命错误的地方,因为错误消息如下:

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

在我更新到所有内容的最新版本之前,这一切似乎都运行良好,但我不确定发生了什么变化。

【问题讨论】:

  • 您从gameViewController 发布了一个初始化程序,警告是关于GameOptionsViewController。您确定您查看的是正确的文件吗?
  • 将您的项目从 Swift 1.2 转换为 swift 2.0 应该会自动解决这个问题。您是否使用 xcode 转换了您的项目?顺便说一句,马特给你的答案是正确的! Start converter Swift 1.2 to 2.0
  • 是的,我使用 swift 进行了升级,但它并没有为我解决这个问题……奇怪

标签: ios xcode swift swift2


【解决方案1】:

这样改写:

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

注意第一行的问号,最后一行没有感叹号。

【讨论】:

  • “?”是什么意思?在这个函数实例中做什么?
猜你喜欢
  • 1970-01-01
  • 2022-01-23
  • 2019-09-17
  • 1970-01-01
  • 1970-01-01
  • 2014-07-25
  • 2016-12-22
  • 1970-01-01
相关资源
最近更新 更多