[swift-users] Where CodingKey protocol is implemented on swift source code

Itai Ferber iferber at apple.com
Wed Oct 4 17:21:41 CDT 2017


Hi Solli,

`CodingKey` conformance for `enum`s is synthesized by the compiler given 
certain rules — you can see mention of this in the [Codable 
proposal](https://github.com/apple/swift-evolution/blob/master/proposals/0166-swift-archival-serialization.md) 
[search for `public protocol CodingKey`].
If you’re interested in specific implementation for how the compiler 
does this, you can refer to 
[lib/Sema/DerivedConformanceCodingKey.cpp](https://github.com/apple/swift/blob/master/lib/Sema/DerivedConformanceCodingKey.cpp).

Happy to answer any questions on this you might have.

— Itai

On 4 Oct 2017, at 14:50, Solli Honorio via swift-users wrote:

> Studying "Codable.swift" and "JSONEncoder.swift" to understand how 
> decoding
> works under the hood, I got confused about how CodingKey is 
> implemented for
> 'enum'. Shouldn't have an extension of RawRepresentable to implement 
> the
> CodingKey protocol?
>
> This is the answer I'm looking for, how the CodingKey protocol is
> implemented on enum?
>
> I appreciate any help, tks
>
> Solli Honorio
>
> -- 
> "o animal satisfeito dorme". - Guimarães Rosa
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171004/0e56140f/attachment.html>


More information about the swift-users mailing list