[swift-evolution] Smart KeyPaths
brent at architechies.com
Wed Mar 29 21:18:04 CDT 2017
> On Mar 29, 2017, at 7:05 PM, Joe Groff <jgroff at apple.com> wrote:
> KeyPath objects themselves have properties, so key1 could be a member of KeyPath. This doesn't seem workable.
Yeah, someone pointed that out to me privately. One solution would be to make it so that an uninterrupted chain of property and subscript references is treated as constructing a key path, but parenthesizing ends the key path construction and accesses its properties instead:
#keyPath(Person).friends.name // Key path to the `name` property of a `Person`
(#keyPath(Person).friends).name // Value of the `name` property of a `WritableKeyPath<Person, Person>`
Optional chaining behaves the same way, and in practice it seems to work fine.
In practice, I'm not sure this would come up very often, because I don't think you're likely to construct a key path and immediately start calling properties on it. But it is a concern.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution