thoughtbot/Argo

RFC: Make Swift.Decodable conform to Argo.Decodable in Swift 4.1

mdiep opened this issue · 4 comments

mdiep commented

I just had this idea, so it's possible it may not work, but…

The automatic synthesis of Swift.Decodable conformance is great… when you can use it. But IMO writing a custom decoder is much easier, flexible, and understandable with Argo.

So… what if Swift.Decodable conformed to Argo.Decodable with a default implementation?

  1. Write ArgoDecoder, which is a Swift.Decoder that decodes from a JSON (or whatever the new type is)
  2. Make Swift.Decodable conform to Argo.Decodable and add a default decode function that uses an ArgoDecoder

Then you'd be able to use any Swift.Decodable type natively with Argo. For any type that maps onto the JSON well, throw on Swift.Decodable and use the synthesized decoder. For anything else, use Argo—even if that type's properties use a synthesized decoder.

oh wow, if this is possible it would be amazing!

mdiep commented

I've decided this should even be possible to do in Swift 4.0, although a little less elegantly, with additional operator overloads. I'm going to try to find to play around with the idea.

I implemented what @mdiep suggested. You can find the relevant blog post and code here:

https://medium.com/@elenipapanikolo/migrating-to-codable-from-a-third-party-parsing-library-fd85298ef5a2

I'm going to go ahead and close this due to inactivity but please feel free to reopen if this is still an issue.