更新到 Xcode 9.3(使用 Swift 4.1)后,发现以下问题:
创建一个空项目,向其中添加一个新的 .swift 文件并创建两个新类:
class CodableOne: Codable { let some: String } class CodableTwo: Codable { var some: String }
构建成功
向
CodableOne
添加一个类型为CodableTwo
的新常量:class CodableOne: Codable { let some: String let another: CodableTwo } class CodableTwo: Codable { var some: String }
构建成功
现在将类
CodableTwo
移动到另一个文件(例如 ViewController.swift)构建失败。
现在有一个错误,不会消失。 Codable
类不应需要初始化程序(如前面的步骤所示)。
任何关于这背后可能是什么问题以及如何解决它的想法将不胜感激!
附言Xcode 9.2 中不存在此问题。既不清理项目/构建路径,重新安装 Xcode 9.3 也无济于事。
最佳答案
作为mentioned in the comments ,我必须做两件事:
关于swift - Xcode 9.3 (Swift 4.1) 中的 Codable 'has no initializers',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49582558/