Where CodingKey protocol is implemented on swift source code

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

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@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

1 Like

Thanks for the clarification.

···

Em qua, 4 de out de 2017 às 19:21, Itai Ferber <iferber@apple.com> escreveu:

Hi Solli,

CodingKey conformance for enums 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&gt;
[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&gt;
.

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@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

--

Enviado do Gmail para celular