<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="">Proposal Link: <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0161-key-paths.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0161-key-paths.md</a><div class=""><br class=""></div><div class="">The second review of SE-0161 "Smart KeyPaths: Better Key-Value Coding for Swift” ran April 5...9, 2017. The <a href="https://lists.swift.org/pipermail/swift-evolution-announce/2017-April/000342.html" class="">first review</a> established the main substance of the proposal, while the second review focused mostly on the more lightweight “\” syntax. The proposal is <b class="">accepted</b> with one clarification regarding the intersection between contextual keypaths (where the base type is left unspecified) and array types.</div><div class=""><br class=""></div><div class="">The core team felt that the leading “<font face="Menlo" class="">\</font>” is our best option for introducing keypaths. It is lightweight, yet provides a visual “escape” to indicate that the evaluation of the entities being referenced is being delayed. As noted in the result of the <a href="https://lists.swift.org/pipermail/swift-evolution-announce/2017-April/000342.html" class="">first review</a>, this is part of a longer-term plan to use the “<font face="Menlo" class="">\</font>” for unapplied method references, bringing the two closely-related features into syntactic alignment over time and providing an opportunity to stage in the important but currently-source-breaking changes accepted in <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0042-flatten-method-types.md" class="">SE-0042</a>.</div><div class=""><br class=""></div><div class="">Much discussion centered around potential ambiguities. Accessing a property of a key path, e.g., <font face="Menlo" class="">\Person.friends[0].firstName.someKeyPathProperty</font>, requires one to parenthesize the key path as (<font face="Menlo" class="">\Person.friends[0].firstName).someKeyPathProperty</font>, which is a common way to disambiguate expressions in Swift (and most other programming languages) already. More concerning to the core team was the ambiguity between contextual keypaths starting with a subscript and keypaths rooted on an array type, e.g.,</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>\[a]?.foo // is [a]? a type rooting a keypath “.foo”</font></div><div class=""><font face="Menlo" class=""> // or is it a contextual keypath starting with a subscript [a]?</font></div><div class=""><br class=""></div><div class="">To resolve this ambiguity, *all* contextual keypaths will start with “<font face="Menlo" class="">\.</font>”. The expression above will use the first interpretation (a type <font face="Menlo" class="">[a]?</font> rooting a key path “<font face="Menlo" class="">.foo</font>”), while the second interpretation would be written as:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>\.[a]?.foo // a contextual key path starting with the subscript [a]</font></div><div class=""><br class=""></div><div class="">The core team felt that the result is more consistent: “<font face="Menlo" class="">\.</font>” indicates a contextual keypath, while “<font face="Menlo" class="">\</font>” without the “<font face="Menlo" class="">.</font>” indicates a keypath with a specified root.</div><div class=""><br class=""></div><div class="">The authors will revise the proposal according. Thank you to everyone who participated in the reviews of this much-anticipated feature!</div><div class=""><br class=""></div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>- Doug</div><div class=""><span class="Apple-tab-span" style="white-space:pre">        </span>Review Manager</div><div class=""><br class=""></div></body></html>