[swift-evolution] [Discussion] Referencing the Objective-C selector of property getters and setters

David Hart david at hartbit.com
Thu Feb 25 01:38:22 CST 2016

Now that I’m thinking about it, wouldn’t my need be better served by a different proposal for:

#key(Person.firstName) // returns the string “firstName”
#keyPath(Person.mother.firstName) // returns the string “mother.firstName”

How doable is the keyPath version?

> On 25 Feb 2016, at 08:10, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
> In the original thread, my use case was the ability to get type-safety for key-value coding:
> david.setValue(30, forKey: String(#selector(getter: Person.age)))
> On 25 Feb 2016, at 06:50, Brent Royal-Gordon <brent at architechies.com> wrote:
>>> Motivation
>>> The #selector feature is very useful but does not yet cover all cases. Accessing poperty getter and setters requires to drop down to the string syntax and forgo type-safety. This proposal supports this special case without introducing new syntax, but by introducing new overloads to the #selector compiler expression.
>> What I don't understand is, what's the use case? When you want to access properties dynamically in Objective-C, you usually use key-value coding, not selectors. Can you point to APIs it would be helpful to use this with, or write some realistic code which uses this feature? Or is this basically just completeness for the sake of completeness?
>> -- 
>> Brent Royal-Gordon
>> Architechies
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

More information about the swift-evolution mailing list