[swift-evolution] SE-0062 Referencing Objective-C key-paths

Douglas Gregor dgregor at apple.com
Tue Apr 12 11:35:14 CDT 2016

> On Apr 7, 2016, at 9:34 PM, Les Pruszynski via swift-evolution <swift-evolution at swift.org> wrote:
> This is my first post on this list so please bear with me.
> I very much like this proposal but what bothers me is this doubling of valueForKeyPath(#keyPath(xxx) in the signature of the function.
> chris.valueForKeyPath(#keyPath(Person.bestFriend.lastName)) // => Groff
> chris.valueForKeyPath(#keyPath(Person.friends.firstName)) // => ["Joe", "Douglas"]
> I’m not sure whether the form below is actually possible. For me it reads more naturally and is more consistent with “Modern Swift” as far as I know.
> chris.valueFor(#keyPath(Person.friends.firstName)) // => ["Joe", "Douglas”]
> or maybe
> chris.valueOf(#keyPath(Person.friends.firstName)) // => ["Joe", "Douglas”]

If key paths were some stronger type (as Brent is suggesting), we could do this. However, because key paths are just Strings, we need to compensate for weak type information <https://swift.org/documentation/api-design-guidelines/#promote-clear-usage>, so valueForKeyPath should retain it’s currently name despite the redundancy in many use sites with #keyPath.

	- Doug

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160412/6dc6d703/attachment.html>

More information about the swift-evolution mailing list