<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"> </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> @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> @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<Root : Codable> {</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> open func decode(for keyPath: KeyPath<Root, Bool>) throws -> Bool</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> open func decode(for keyPath: KeyPath<Root, Int>) throws -> Int</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> open func decode(for keyPath: KeyPath<Root, UInt>) throws -> UInt</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> open func decode(for keyPath: KeyPath<Root, Float>) throws -> Float</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> open func decode(for keyPath: KeyPath<Root, Double>) throws -> Double</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> open func decode(for keyPath: KeyPath<Root, String>) throws -> String</font></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span> open func decode(for keyPath: KeyPath<Root, Data>) throws -> 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> open func decode<Value : Codable>(for keyPath: KeyPath<Root, Value>) throws -> 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>