> On Apr 7, 2016, at 9:34 PM, Les Pruszynski via swift-evolution 
> <swift-evolution@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


_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to