Anviking / Decodable

[Probably deprecated] Swift 2/3 JSON unmarshalling done (more) right
MIT License
1.04k stars 73 forks source link

Customization in a framework #137

Open alexito4 opened 7 years ago

alexito4 commented 7 years ago

Hi!

I'm upgrading a framework to Swift 3 and to Decodable 0.5. Before, we used to have a custom conformance to Decodable for Dates that was mapping a timestamp using timeIntervalSince1970, but obviously now that Date has a conformance to Decodable from this library itself we can't do that anymore.

Using the Customization that you provide should work, but the issue is that I'm using Decodable in a framework so there is no "entry point" where I can run the code to setup the decoder function. (I may have one that kind of works for the apps that use the framework, but that won't work for unit tests for example).

I can have a different decode method on Date an call that manually but I was curious if there is something I'm missing.

Cheers.

Anviking commented 7 years ago

Hm, interesting. This would be a concrete reason to remove DynamicDecodable and provide no default implementations of Decodable at all, which I didn't have the guts to do before.

Lascorbe commented 7 years ago

What if the default implementations are available as a separate module? That way everyone can keep using them, and those of us who don't want a default impl, just don't import it :)

Anviking commented 7 years ago

I realised the way SE-0166 stores primitive decoding information in Decoder objects is probably much more sane than Decodable's approach of putting them in protocol conformances. If there is still a place for Decodable in Swift 4, this might be worth looking in to.