【发布时间】:2021-03-09 00:36:04
【问题描述】:
我继承了 Codable 类,如下所示。
class Vehicle: Codable {
let id: Int
let name: String
init(id: Int, name: String) {
self.id = id
self.name = name
}
}
class Car: Vehicle {
let type: String
init(id: Int, name: String, type: String) {
self.type = type
super.init(id: id, name: name)
}
}
显示错误
'required' initializer 'init(from:)' must be provided by subclass of 'Vehicle'
什么是继承可编码类的正确方法?
【问题讨论】:
标签: swift inheritance codable