7
在带有继承的Swift 4中使用Decodable
使用类继承是否会破坏类的可解码性。例如下面的代码 class Server : Codable { var id : Int? } class Development : Server { var name : String? var userId : Int? } var json = "{\"id\" : 1,\"name\" : \"Large Building Development\"}" let jsonDecoder = JSONDecoder() let item = try jsonDecoder.decode(Development.self, from:json.data(using: .utf8)!) as Development print(item.id ?? …