Slide 16
Slide 16 text
JSON
とstruct
の構造が違う
init
を自分で実装する(めんどくさい)
decode
のキーはいずれもtarget
を使う
...
public init(from decoder: Decoder) throws {
let values = try decoder.container(keyedBy: CodingKeys.
type = try values.decode(String.self, forKey: .type)
if type == "user" {
user = try values.decode(User.self, forKey: .target)
} else if type == "store" {
store = try values.decode(Store.self, forKey: .target)
}
}
}