Why #Codable# not working in below code?
问题 I have below code to test Codable protocol and JSONDecoder . import UIKit class ClassA: Codable { var age: Int = 1 } class ClassB: Codable { var ageInfo: ClassA? var name: String } let json4 = """ { "ageInfo": {}, "name": "Jack" } """.data(using: .utf8)! do { let d = try JSONDecoder().decode(ClassB.self, from: json4) } catch let err { print(err) } My question is, why json4 can't be decode? or how I can decode json4 ? 回答1: age in ClassA is declared non-optional so the key is required however