<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 22 Mar 2017, at 17:41, Itai Ferber wrote:</div><br class="Apple-interchange-newline"><div class=""><p dir="auto" style="font-family: sans-serif; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">What’s the use case that you were thinking of?<span class="Apple-converted-space">&nbsp;</span><code bgcolor="#F7F7F7" style="background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; margin: 0px; padding: 0px 0.4em;" class="">KeyPath</code>s could be useful in the case where you don’t need to customize your key names, but cannot represent a custom case like</p><pre bgcolor="#F7F7F7" style="font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(247, 247, 247); border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; margin-left: 15px; margin-right: 15px; max-width: 90vw; overflow-x: auto; padding: 5px;" class=""><code bgcolor="#F7F7F7" style="background-color: rgb(247, 247, 247); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; margin: 0px; padding: 0px;" class=""><span style="color: rgb(0, 136, 0); font-weight: bold;" class="">public</span> <span style="color: rgb(0, 136, 0); font-weight: bold;" class="">struct</span> <span style="color: rgb(187, 0, 102); font-weight: bold;" class="">Post</span> {
    <span style="color: rgb(0, 136, 0); font-weight: bold;" class="">var</span> <span style="color: rgb(153, 102, 51);" class="">authorID</span>: <span style="color: rgb(0, 112, 32);" class="">Int</span>
    <span style="color: rgb(0, 136, 0); font-weight: bold;" class="">var</span> <span style="color: rgb(153, 102, 51);" class="">bodyText</span>: <span style="color: rgb(0, 112, 32);" class="">String</span>

    <span style="color: rgb(0, 136, 0); font-weight: bold;" class="">private</span> <span style="color: rgb(0, 136, 0); font-weight: bold;" class="">enum</span> <span style="color: rgb(187, 0, 102); font-weight: bold;" class="">CodingKeys</span> : <span style="color: rgb(0, 112, 32);" class="">String</span>, CodingKey {
        <span style="color: rgb(0, 136, 0); font-weight: bold;" class="">case</span> authorID = <span style="background-color: rgb(255, 240, 240);" class="">"author_id"</span>
        <span style="color: rgb(0, 136, 0); font-weight: bold;" class="">case</span> bodyText = <span style="background-color: rgb(255, 240, 240);" class="">"body_text"</span>
    }
}
</code></pre><p dir="auto" style="font-family: sans-serif; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Or am I misunderstanding?</p></div></blockquote></div><br class=""><div class=""><div class="">For custom names, the `CodingKeys` enum does seem like the best design, unless an attribute can be used.</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>public struct Post : Codable {</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;@codable(name: "author_id") var authorID: Int</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;@codable(name: "body_text") var bodyText: String</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><br class=""></div><div class="">If each `KeyPath` encapsulates the type information, the `decode` methods won't need a `type` parameter.</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Primitive decoding methods (for single-value and keyed containers).</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>open class DecodingContainer&lt;Root : Codable&gt; {</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;open func decode(for keyPath: KeyPath&lt;Root, Bool&gt;) &nbsp; throws -&gt; Bool</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;open func decode(for keyPath: KeyPath&lt;Root, Int&gt;) &nbsp; &nbsp;throws -&gt; Int</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;open func decode(for keyPath: KeyPath&lt;Root, UInt&gt;) &nbsp; throws -&gt; UInt</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;open func decode(for keyPath: KeyPath&lt;Root, Float&gt;) &nbsp;throws -&gt; Float</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;open func decode(for keyPath: KeyPath&lt;Root, Double&gt;) throws -&gt; Double</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;open func decode(for keyPath: KeyPath&lt;Root, String&gt;) throws -&gt; String</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;open func decode(for keyPath: KeyPath&lt;Root, Data&gt;) &nbsp; throws -&gt; Data</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>/// Keyed containers inherit the primitive decoding methods.</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>open class KeyedDecodingContainer : DecodingContainer {</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> &nbsp; &nbsp;open func decode&lt;Value : Codable&gt;(for keyPath: KeyPath&lt;Root, Value&gt;) throws -&gt; Value</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>}</font></div><div class=""><br class=""></div><div class="">-- Ben</div></div><div class=""><br class=""></div></body></html>