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 a Swift.Decoder that decodes from a JSON (or whatever the new type is)
- 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.
I just had this idea, so it's possible it may not work, but…
The automatic synthesis of
Swift.Decodableconformance 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.Decodableconformed toArgo.Decodablewith a default implementation?ArgoDecoder, which is aSwift.Decoderthat decodes from aJSON(or whatever the new type is)Swift.Decodableconform toArgo.Decodableand add a defaultdecodefunction that uses anArgoDecoderThen you'd be able to use any
Swift.Decodabletype natively with Argo. For any type that maps onto the JSON well, throw onSwift.Decodableand use the synthesized decoder. For anything else, use Argo—even if that type's properties use a synthesized decoder.