RFC: Make Swift.Decodable conform to Argo.Decodable in Swift 4.1
mdiep opened this issue · 4 comments
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?
- Write
ArgoDecoder
, which is aSwift.Decoder
that decodes from aJSON
(or whatever the new type is) - Make
Swift.Decodable
conform toArgo.Decodable
and add a defaultdecode
function that uses anArgoDecoder
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!
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:
I'm going to go ahead and close this due to inactivity but please feel free to reopen if this is still an issue.