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

Keith Smiley keithbsmiley at gmail.com
Tue Mar 15 12:57:40 CDT 2016


Maybe it would be nice if we preferred getters instead? Since I (making a
totally unfounded assumption) assume that would be used more. But either way, I
just wanted to show a quick example of the problem, I'm personally less worried
about the exact syntax.

--
Keith Smiley

On 03/15, David Hart wrote:
> Wouldn't it be:
>
> #selector(getter: NSString.lowercaseString))
>
> To allow us to disambiguate getters and setters?
>
> > On 15 Mar 2016, at 06:09, Keith Smiley <keithbsmiley at gmail.com> wrote:
> >
> > Another reasonable use case for this is with `UILocalizedIndexedCollation`. For example with Swift 2.1:
> >
> > ```
> > let collation = UILocalizedIndexedCollation.currentCollation()
> > collation.sectionForObject("something", collationStringSelector: "lowercaseString") // NSString.lowercaseString
> > ```
> >
> > Currently the Xcode quickfix is:
> >
> > ```
> > collation.sectionForObject("something", collationStringSelector: Selector("lowercaseString"))
> > ```
> >
> > But I guess ideally this would work something like:
> >
> > ```
> > collation.sectionForObject("something", collationStringSelector: #selector(NSString.lowercaseString))
> >
> > --
> > Keith Smiley
> >
> > On 02/24, Brent Royal-Gordon via swift-evolution 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