<div dir="ltr">Hi Itai,<div><br></div><div>Glad to see these proposal! I'm curious, have you or the other Swift folks thought about how *users* of these new Codable protocols will interact with resilience domains?</div><div><br></div><div>What I mean is that what appear to be private or internal identifiers, and thus changeable at will, may actually be fragile in that changing them will break the ability to decode archives encoded by previous versions.</div><div><br></div><div>Making this safer could mean:</div><div>- Encoding only public properties</div><div>- Adding some form of indirection (a la ObjC non-fragile ivars?)</div><div>- Compiler warning (or disallowing) changes to properties in certain situations.</div><div><br></div><div>I imagine the specifics would need to follow the rest of the plans for resilience.</div><div><br></div><div>It's likely that this could be addressed by a future proposal, as for the time being developers can simply "not hold it wrong" ;)</div><div><br></div><div>Thanks,</div><div>-Colin</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 15, 2017 at 6:52 PM Itai Ferber via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="gmail_msg"><span style="background-color:rgb(255,255,255);font-size:14px" class="gmail_msg">Hi everyone,</span><div class="gmail_msg"><span style="background-color:rgb(255,255,255);font-size:14px" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="background-color:rgb(255,255,255)" class="gmail_msg"><span style="font-size:14px" class="gmail_msg">The following introduces a new Swift-focused archival and serialization API as part of the Foundation framework. We’re interested in improving the experience and safety of performing archival and serialization, and are happy to receive community feedback on this work.</span></span></div><div class="gmail_msg"><span style="background-color:rgb(255,255,255)" class="gmail_msg"><span style="font-size:14px" class="gmail_msg">Because of the length of this proposal, the <b class="gmail_msg">Appendix</b> and <b class="gmail_msg">Alternatives Considered</b> sections have been omitted here, but are available in the </span></span><a href="https://github.com/apple/swift-evolution/pull/639" style="font-size:14px" class="gmail_msg" target="_blank">full proposal</a><span style="font-size:14px" class="gmail_msg"> on the swift-evolution repo. The full proposal also includes an <b class="gmail_msg">Unabridged API</b> for further consideration.</span></div><div class="gmail_msg"><span style="font-size:14px" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="font-size:14px" class="gmail_msg">Without further ado, inlined below.</span></div><div class="gmail_msg"><span style="font-size:14px" class="gmail_msg"><br class="gmail_msg"></span></div><div class="gmail_msg"><span style="font-size:14px" class="gmail_msg">— Itai</span></div><div class="gmail_msg"><span style="font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><br class="gmail_msg"></span><h1 id="m_8970768481418073780toc_0" style="margin:0px 0px 10px;padding:0px;font-size:28px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)" class="gmail_msg">Swift Archival & Serialization</h1><ul style="margin:15px 0px;padding-left:30px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="margin:0px" class="gmail_msg">Proposal: <a href="https://github.com/apple/swift-evolution/pull/639" class="gmail_msg" target="_blank">SE-NNNN</a></li><li style="margin:0px" class="gmail_msg">Author(s): <a href="https://github.com/itaiferber" style="color:rgb(65,131,196);margin-top:0px" class="gmail_msg" target="_blank">Itai Ferber</a>, <a href="https://github.com/mlehew" style="color:rgb(65,131,196)" class="gmail_msg" target="_blank">Michael LeHew</a>, <a href="https://github.com/parkera" style="color:rgb(65,131,196)" class="gmail_msg" target="_blank">Tony Parker</a></li><li style="margin:0px" class="gmail_msg">Review Manager: TBD</li><li style="margin:0px" class="gmail_msg">Status: <strong style="margin-top:0px" class="gmail_msg">Awaiting review</strong></li><li style="margin:0px" class="gmail_msg">Associated PRs:<ul style="margin:0px 0px 15px;padding-left:30px" class="gmail_msg"><li style="margin:0px" class="gmail_msg"><a href="https://github.com/apple/swift/pull/8124" style="color:rgb(65,131,196);margin-top:0px" class="gmail_msg" target="_blank">#8124</a></li><li style="margin:0px" class="gmail_msg"><a href="https://github.com/apple/swift/pull/8125" style="color:rgb(65,131,196);margin-top:0px" class="gmail_msg" target="_blank">#8125</a></li></ul></li></ul><h2 id="m_8970768481418073780toc_1" style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)" class="gmail_msg">Introduction</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">Foundation's current archival and serialization APIs (<code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">NSCoding</code>, <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">NSJSONSerialization</code>, <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">NSPropertyListSerialization</code>, etc.), while fitting for the dynamism of Objective-C, do not always map optimally into Swift. This document lays out the design of an updated API that improves the developer experience of performing archival and serialization in Swift.</p><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">Specifically:</p><ul style="margin:15px 0px;padding-left:30px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="margin:0px" class="gmail_msg">It aims to provide a solution for the archival of Swift <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">struct</code> and <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enum</code> types</li><li style="margin:0px" class="gmail_msg">It aims to provide a more type-safe solution for serializing to external formats, such as JSON and plist</li></ul><h2 id="m_8970768481418073780toc_2" style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)" class="gmail_msg">Motivation</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">The primary motivation for this proposal is the inclusion of native Swift <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enum</code> and <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">struct</code> types in archival and serialization. Currently, developers targeting Swift cannot participate in <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">NSCoding</code> without being willing to abandon <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enum</code> and <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">struct</code>types — <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">NSCoding</code> is an <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">@objc</code> protocol, conformance to which excludes non-<code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">class</code> types. This is can be limiting in Swift because small <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enums</code> and <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">structs</code> can be an idiomatic approach to model representation; developers who wish to perform archival have to either forgo the Swift niceties that constructs like <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enums</code>provide, or provide an additional compatibility layer between their "real" types and their archivable types.</p><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">Secondarily, we would like to refine Foundation's existing serialization APIs (<code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">NSJSONSerialization</code> and <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">NSPropertyListSerialization</code>) to better match Swift's strong type safety. From experience, we find that the conversion from the unstructured, untyped data of these formats into strongly-typed data structures is a good fit for archival mechanisms, rather than taking the less safe approach that 3rd-party JSON conversion approaches have taken (described further in an appendix below).</p><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">We would like to offer a solution to these problems without sacrificing ease of use or type safety.</p><h2 id="m_8970768481418073780toc_3" style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)" class="gmail_msg">Agenda</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">This proposal is the first stage of three that introduce different facets of a whole Swift archival and serialization API:</p><ol style="margin:15px 0px;padding-left:30px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="margin:0px" class="gmail_msg">This proposal describes the basis for this API, focusing on the protocols that users adopt and interface with</li><li style="margin:0px" class="gmail_msg">The next stage will propose specific API for new encoders</li><li style="margin:0px" class="gmail_msg">The final stage will discuss how this new API will interop with <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">NSCoding</code> as it is today</li></ol><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">SE-NNNN provides stages 2 and 3.</p><h2 id="m_8970768481418073780toc_4" style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)" class="gmail_msg">Proposed solution</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">We will be introducing the following new types:</p><ul style="margin:15px 0px;padding-left:30px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="margin:0px" class="gmail_msg"><code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">protocol Codable</code>: Adopted by types to opt into archival. Conformance may be automatically derived in cases where all properties are also <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code>.</li><li style="margin:0px" class="gmail_msg"><code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">protocol CodingKey</code>: Adopted by types used as keys for keyed containers, replacing <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">String</code> keys with semantic types. Conformance may be automatically derived in most cases.</li><li style="margin:0px" class="gmail_msg"><code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">protocol Encoder</code>: Adopted by types which can take <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code> values and encode them into a native format.<ul style="margin:15px 0px;padding-left:30px" class="gmail_msg"><li style="margin:0px" class="gmail_msg"><code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">class KeyedEncodingContainer<Key : CodingKey></code>: Subclasses of this type provide a concrete way to store encoded values by <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">CodingKey</code>. Types adopting <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Encoder</code> should provide subclasses of <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">KeyedEncodingContainer</code> to vend.</li><li style="margin:0px" class="gmail_msg"><code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">protocol SingleValueEncodingContainer</code>: Adopted by types which provide a concrete way to store a single encoded value. Types adopting <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Encoder</code> should provide types conforming to <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">SingleValueEncodingContainer</code> to vend (but in many cases will be able to conform to it themselves).</li></ul></li><li style="margin:0px" class="gmail_msg"><code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">protocol Decoder</code>: Adopted by types which can take payloads in a native format and decode <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code> values out of them.<ul style="margin:15px 0px;padding-left:30px" class="gmail_msg"><li style="margin:0px" class="gmail_msg"><code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">class KeyedDecodingContainer<Key : CodingKey></code>: Subclasses of this type provide a concrete way to retrieve encoded values from storage by <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">CodingKey</code>. Types adopting <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Decoder</code> should provide subclasses of <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">KeyedDecodingContainer</code> to vend.</li><li style="margin:0px" class="gmail_msg"><code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">protocol SingleValueDecodingContainer</code>: Adopted by types which provide a concrete way to retrieve a single encoded value from storage. Types adopting <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Decoder</code> should provide types conforming to <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">SingleValueDecodingContainer</code> to vend (but in many cases will be able to conform to it themselves).</li></ul></li></ul><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">For end users of this API, adoption will primarily involve the <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code> and <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">CodingKey</code> protocols. In order to participate in this new archival system, developers must add <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code> conformance to their types:</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><pre class="m_8970768481418073780language-swift gmail_msg" style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;white-space:pre-wrap;word-spacing:normal;word-break:normal;word-wrap:normal"><code class="m_8970768481418073780language-swift gmail_msg" style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// If all properties are Codable, implementation is automatically derived:</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">struct</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Location</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Codable</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> latitude<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Double</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> longitude<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Double</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">enum</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Animal</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Int</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Codable</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> chicken <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span class="m_8970768481418073780token m_8970768481418073780number gmail_msg" style="color:rgb(153,0,85)">1</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> dog
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> turkey
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> cow
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">struct</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Farm</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Codable</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> name<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">String</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> location<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Location</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> animals<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">[</span><span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Animal</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">]</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span></code></pre></div><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">With developer participation, we will offer encoders and decoders (described in SE-NNNN, not here) that take advantage of this conformance to offer type-safe serialization of user models:</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><pre class="m_8970768481418073780language-swift gmail_msg" style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;white-space:pre-wrap;word-spacing:normal;word-break:normal;word-wrap:normal"><code class="m_8970768481418073780language-swift gmail_msg" style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> farm <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">Farm</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>name<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780string gmail_msg" style="color:rgb(102,153,0)">"Old MacDonald's Farm"</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span>
location<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">Location</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>latitude<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780number gmail_msg" style="color:rgb(153,0,85)">51.621648</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> longitude<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780number gmail_msg" style="color:rgb(153,0,85)">0.269273</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span>
animals<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">[</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>chicken<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>dog<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>cow<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>turkey<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>dog<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>chicken<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>cow<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>turkey<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>dog<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">]</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> payload<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Data</span> <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">try</span> <span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">JSONEncoder</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">encode</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>farm<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">do</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> farm <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">try</span> <span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">JSONDecoder</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">decode</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span><span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Farm</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">self</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> from<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> payload<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// Extracted as user types:</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> coordinates <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span class="m_8970768481418073780token m_8970768481418073780string gmail_msg" style="color:rgb(102,153,0)">"<span class="m_8970768481418073780token m_8970768481418073780interpolation gmail_msg"><span class="m_8970768481418073780token m_8970768481418073780delimiter m_8970768481418073780variable gmail_msg" style="color:rgb(238,153,0)">\(</span>farm<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>location<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>latitude<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> farm<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>location<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>longitude<span class="m_8970768481418073780token m_8970768481418073780delimiter m_8970768481418073780variable gmail_msg" style="color:rgb(238,153,0)">)</span></span>"</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">catch</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// Encountered error during deserialization</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span></code></pre></div><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">This gives developers access to their data in a type-safe manner and a recognizable interface.</p><h2 id="m_8970768481418073780toc_5" style="margin:20px 0px 10px;padding:0px;font-size:24px;border-bottom-width:1px;border-bottom-style:solid;border-bottom-color:rgb(204,204,204);font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)" class="gmail_msg">Detailed design</h2><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">To support user types, we expose the <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code> protocol:</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><pre class="m_8970768481418073780language-swift gmail_msg" style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;white-space:pre-wrap;word-spacing:normal;word-break:normal;word-wrap:normal"><code class="m_8970768481418073780language-swift gmail_msg" style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// Conformance to `Codable` indicates that a type can marshal itself into and out of an external representation.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> protocol <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Codable</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// Initializes `self` by decoding from `decoder`.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">///</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - parameter decoder: The decoder to read data from.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - throws: An error if reading from the decoder fails, or if read data is corrupted or otherwise invalid.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">init</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>from decoder<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Decoder</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">throws</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// Encodes `self` into the given encoder.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">///</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// If `self` fails to encode anything, `encoder` will encode an empty `.default` container in its place.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">///</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - parameter encoder: The encoder to write data to.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - throws: An error if any values are invalid for `encoder`'s format.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">func</span> <span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">encode</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>to encoder<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Encoder</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">throws</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span></code></pre></div><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">By adopting <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code>, user types opt in to this archival system.</p><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">Structured types (i.e. types which encode as a collection of properties) encode and decode their properties in a keyed manner. Keys may be <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">String</code>-convertible or <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Int</code>-convertible (or both), and user types which have properties should declare semantic key <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enums</code> which map keys to their properties. Keys must conform to the <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">CodingKey</code> protocol:</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><pre class="m_8970768481418073780language-swift gmail_msg" style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;white-space:pre-wrap;word-spacing:normal;word-break:normal;word-wrap:normal"><code class="m_8970768481418073780language-swift gmail_msg" style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// Conformance to `CodingKey` indicates that a type can be used as a key for encoding and decoding.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> protocol <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKey</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// The string to use in a named collection (e.g. a string-keyed dictionary).</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">var</span> stringValue<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">String</span><span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">get</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// Initializes `self` from a string.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">///</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - parameter stringValue: The string value of the desired key.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - returns: An instance of `Self` from the given string, or `nil` if the given string does not correspond to any instance of `Self`.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">init</span><span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>stringValue<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">String</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// The int to use in an indexed collection (e.g. an int-keyed dictionary).</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">var</span> intValue<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Int</span><span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">get</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// Initializes `self` from an integer.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">///</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - parameter intValue: The integer value of the desired key.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - returns: An instance of `Self` from the given integer, or `nil` if the given integer does not correspond to any instance of `Self`.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">init</span><span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">?</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>intValue<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Int</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span></code></pre></div><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">For most types, <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">String</code>-convertible keys are a reasonable default; for performance, however, <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Int</code>-convertible keys are preferred, and <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Encoders</code> may choose to make use of <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Ints</code> over <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Strings</code>. Framework types should provide keys which have both for flexibility and performance across different types of <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Encoders</code>. It is generally an error to provide a key which has neither a <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">stringValue</code> nor an <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">intValue</code>.</p><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">By default, <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">CodingKey</code> conformance can be derived for <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enums</code> which have either <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">String</code> or <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Int</code> backing:</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><pre class="m_8970768481418073780language-swift gmail_msg" style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;white-space:pre-wrap;word-spacing:normal;word-break:normal;word-wrap:normal"><code class="m_8970768481418073780language-swift gmail_msg" style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">enum</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Keys1</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKey</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> a <span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// (stringValue: "a", intValue: nil)</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> b <span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// (stringValue: "b", intValue: nil)</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">enum</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Keys2</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">String</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKey</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> c <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span class="m_8970768481418073780token m_8970768481418073780string gmail_msg" style="color:rgb(102,153,0)">"foo"</span> <span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// (stringValue: "foo", intValue: nil)</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> d <span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// (stringValue: "d", intValue: nil)</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">enum</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Keys3</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Int</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKey</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> e <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span class="m_8970768481418073780token m_8970768481418073780number gmail_msg" style="color:rgb(153,0,85)">4</span> <span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// (stringValue: "e", intValue: 4)</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> f <span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// (stringValue: "f", intValue: 5)</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> g <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> <span class="m_8970768481418073780token m_8970768481418073780number gmail_msg" style="color:rgb(153,0,85)">9</span> <span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// (stringValue: "g", intValue: 9)</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span></code></pre></div><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">Coding keys which are not <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enum</code>s, have associated values, or have other raw representations must implement these methods manually.</p><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">In addition to automatic <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">CodingKey</code> conformance derivation for <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enum</code>s, <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code>conformance can be automatically derived for certain types as well:</p><ol style="margin:15px 0px;padding-left:30px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><li style="margin:0px" class="gmail_msg">Types whose properties are all either <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code> or primitive get an automatically derived <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">String</code>-backed <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">CodingKeys</code> <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enum</code> mapping properties to case names</li><li style="margin:0px" class="gmail_msg">Types falling into (1) and types which provide a <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">CodingKeys</code> <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">enum</code> (directly or via a <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">typealias</code>) whose case names map to properties which are all <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Codable</code>get automatic derivation of <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">init(from:)</code> and <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">encode(to:)</code> using those properties and keys. Types may choose to provide a custom <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">init(from:)</code> or <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">encode(to:)</code> (or both); whichever they do not provide will be automatically derived</li><li style="margin:0px" class="gmail_msg">Types which fall into neither (1) nor (2) will have to provide a custom key type and provide their own <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">init(from:)</code> and <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">encode(to:)</code></li></ol><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">Many types will either allow for automatic derivation of all codability (1), or provide a custom key subset and take advantage of automatic method derivation (2).</p><h3 id="m_8970768481418073780toc_6" style="margin:20px 0px 10px;padding:0px;font-size:18px;font-family:Helvetica,arial,sans-serif;background-color:rgb(255,255,255)" class="gmail_msg">Encoding and Decoding</h3><p style="margin:15px 0px;font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg">Types which are encodable encode their data into a container provided by their <code style="margin:0px 2px;padding:0px 5px;white-space:nowrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="gmail_msg">Encoder</code>:</p><div style="font-family:Helvetica,arial,sans-serif;font-size:14px;background-color:rgb(255,255,255)" class="gmail_msg"><pre class="m_8970768481418073780language-swift gmail_msg" style="margin-top:0.5em;margin-bottom:0.5em;background-color:rgb(245,242,240);border:1px solid rgb(204,204,204);font-size:13px;line-height:1.5;overflow:auto;padding:1em;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;white-space:pre-wrap;word-spacing:normal;word-break:normal;word-wrap:normal"><code class="m_8970768481418073780language-swift gmail_msg" style="margin:0px;padding:0px;border:none;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;background-image:none;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5"><span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// An `Encoder` is a type which can encode values into a native format for external representation.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> protocol <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Encoder</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// Populates `self` with an encoding container (of `.default` type) and returns it, keyed by the given key type.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">///</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - parameter type: The key type to use for the container.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - returns: A new keyed encoding container.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - precondition: May not be called after a previous `self.container(keyedBy:)` call of a different `EncodingContainerType`.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - precondition: May not be called after a value has been encoded through a prior `self.singleValueContainer()` call.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">func</span> container<span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial"><</span><span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Key</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKey</span><span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">></span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>keyedBy type<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Key</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">Type</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span> <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">></span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">KeyedEncodingContainer</span><span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial"><</span><span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Key</span><span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">></span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// Returns an encoding container appropriate for holding a single primitive value.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">///</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - returns: A new empty single value container.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - precondition: May not be called after a prior `self.container(keyedBy:)` call.</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// - precondition: May not be called after a value has been encoded through a previous `self.singleValueContainer()` call.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">func</span> <span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">singleValueContainer</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span> <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">-</span><span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">></span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">SingleValueEncodingContainer</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">/// The path of coding keys taken to get to this point in encoding.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">var</span> codingKeyContext<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">[</span><span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKey</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">]</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">get</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// Continuing examples from before; below is automatically generated by the compiler if no customization is needed.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">struct</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Location</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Codable</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">private</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">enum</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKeys</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKey</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> latitutude
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> longitude
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">func</span> <span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">encode</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>to encoder<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Encoder</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">throws</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// Generic keyed encoder gives type-safe key access: cannot encode with keys of the wrong type.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> container <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> encoder<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">container</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>keyedBy<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKeys</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">self</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span>
<span class="m_8970768481418073780token m_8970768481418073780comment gmail_msg" style="color:slategray">// The encoder is generic on the key -- free key autocompletion here.</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">try</span> container<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">encode</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>latitude<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> forKey<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>latitude<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">try</span> container<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">encode</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>longitude<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">,</span> forKey<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span>longitude<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">struct</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Farm</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Codable</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">private</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">enum</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKeys</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKey</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> name
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> location
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">case</span> animals
<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">}</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">public</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">func</span> <span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">encode</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>to encoder<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">Encoder</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span> <span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">throws</span> <span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">{</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">let</span> container <span class="m_8970768481418073780token m_8970768481418073780operator gmail_msg" style="color:rgb(166,127,89);background-color:rgba(255,255,255,0.498039);background-position:initial initial;background-repeat:initial initial">=</span> encoder<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">container</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>keyedBy<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">:</span> <span class="m_8970768481418073780token m_8970768481418073780builtin gmail_msg" style="color:rgb(102,153,0)">CodingKeys</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">self</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">)</span>
<span class="m_8970768481418073780token m_8970768481418073780keyword gmail_msg" style="color:rgb(0,119,170)">try</span> container<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">.</span><span class="m_8970768481418073780token m_8970768481418073780function gmail_msg" style="color:rgb(221,74,104)">encode</span><span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)">(</span>name<span class="m_8970768481418073780token m_8970768481418073780punctuation gmail_msg" style="color:rgb(153,153,153)"></span></code></pre></div></div></div></blockquote></div></div>