<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=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><h1 id="toc_0" style="-webkit-print-color-adjust: exact; margin: 0px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; font-size: 28px; font-family: Helvetica, arial, sans-serif; background-color: rgb(255, 255, 255);" class="">Smart KeyPaths: Better Key-Value Coding for Swift</h1><ul style="-webkit-print-color-adjust: exact; margin: 15px 0px; padding-left: 30px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class=""><li style="-webkit-print-color-adjust: exact; margin: 0px;" class="">Proposal: SE-NNNN</li><li style="-webkit-print-color-adjust: exact; margin: 0px;" class="">Authors: <a href="https://github.com/Catfish-Man" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196); margin-top: 0px;" class="">David Smith</a>, <a href="https://github.com/mlehew" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196);" class="">Michael LeHew</a>, <a href="https://github.com/jckarter" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196);" class="">Joe Groff</a></li><li style="-webkit-print-color-adjust: exact; margin: 0px;" class="">Review Manager: TBD</li><li style="-webkit-print-color-adjust: exact; margin: 0px;" class="">Status: <strong style="-webkit-print-color-adjust: exact; margin-top: 0px;" class="">Awaiting Review</strong></li><li style="-webkit-print-color-adjust: exact; margin: 0px;" class="">Associated PRs:<ul style="-webkit-print-color-adjust: exact; margin: 0px 0px 15px; padding-left: 30px;" class=""><li style="-webkit-print-color-adjust: exact; margin: 0px;" class=""><a href="https://github.com/apple/swift-evolution/pull/644" style="-webkit-print-color-adjust: exact; color: rgb(65, 131, 196); margin-top: 0px;" class="">#644</a></li></ul></li></ul><h2 id="toc_1" style="-webkit-print-color-adjust: exact; margin: 20px 0px 10px; padding: 0px; -webkit-font-smoothing: antialiased; cursor: text; position: relative; 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="">Introduction</h2><p style="-webkit-print-color-adjust: exact; margin: 15px 0px; font-family: Helvetica, arial, sans-serif; font-size: 14px; background-color: rgb(255, 255, 255);" class="">We propose a family of concrete <em style="-webkit-print-color-adjust: exact;" class="">Key Path</em> types that represent uninvoked references to properties that can be composed to form paths through many values and directly get/set their underlying values</p></div></div></div></div></blockquote></div><div><br class=""></div><div>Really happy to see this proposal! What isn’t clear to me is if/how this design could also be used for dynamic paths through collections. A concrete use case of this would be getting/setting values in a JSON response consisting of nested dictionaries and arrays.</div><div><br class=""></div><div>I’ve recently started using a design similar to that described by Ole Begemann in this blog post: <a href="https://oleb.net/blog/2017/01/dictionary-key-paths/" class="">https://oleb.net/blog/2017/01/dictionary-key-paths/</a></div><div><br class=""></div><div>That allows me to use strings as key paths to navigate a nested structure:</div><div>data[keyPath: “person.bestFriend.name"] = “Han Solo”</div><div><br class=""></div><div>It uses labeled subscripts to get back values of a known type, which is useful if you want to modify an array for example:</div><div>data[arrayAt: “person.friends"]?.append(["name": “Luke Skywalker”])</div><div><br class=""></div><div>Generic subscripts might make this more elegant, although it seems you’d still need a way to provide enough context to let the type be inferred, and I’m not sure where that information would come from with these dynamic structures.</div><div><br class=""></div><div>Curious to hear if this proposal would help with use cases like this!</div><div><br class=""></div><div>Martijn</div></body></html>