AndyIbanez / andyibanez-com

Static website.
1 stars 0 forks source link

posts/parsing-tricky-json-codable-swift/ #19

Open utterances-bot opened 3 years ago

utterances-bot commented 3 years ago

Parsing Tricky JSON With Codable in Swift • Andy Ibanez

https://www.andyibanez.com/posts/parsing-tricky-json-codable-swift/

igorkravchenko commented 3 years ago

Great article. One thing that may improve and generalize conditional decoding is to introduce enum that conforms to Decodable where each case is generic. This approach is described here. Going further, you can use this enum inside init(from decoder:). Also you can introduce computed properties on the enum to provide value of the type you need by doing desired conversion under the hood.