Slide 11
Slide 11 text
Codable
Decodable
struct User: Codable {
...
private enum CodingKeys: String, CodingKey {
case id, name, age
}
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
id = try container.decode(String.self, forKey: .id)
name = try container.decode(String.self, forKey: .name)
age = try container.decode(Int.self, forKey: .age)
}
}
11