Slide 31
Slide 31 text
來看看有趣的實作
https://github.com/marksands/BetterCodable
Level up your Codable structs through property wrappers. The goal of these
property wrappers is to avoid implementing a custom init(from decoder:
Decoder) throws and suffer through boilerplate.
struct Response: Codable {
@LossyArray var values: [Int]
}
let json = #"{ "values": [1, 2, null, 4, 5, null] }"#.data(using: .utf8)!
let result = try JSONDecoder().decode(Response.self, from: json)
print(result) // [1, 2, 4, 5]
4. BetterCodable