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

Keith Smiley keithbsmiley at gmail.com
Tue Mar 15 00:09:29 CDT 2016


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