[swift-evolution] [Review] SE-0022: Referencing the Objective-C selector of a method

Liam Butler-Lawrence liamdunn at me.com
Thu Jan 21 20:17:33 CST 2016


+1 for #selector(foo).

It emphasizes that this is primarily an Objective-C compatibility feature, not a first-class Swift feature (which the more visually appealing foo.selector would imply). Not to mention that with even moderately long method names, the postfix .selector gets buried visually. With #selector(), on the other hand, a quick glance would always be enough to determine that we are accessing the selector, not the function itself.

> On Jan 21, 2016, at 7:55 PM, Douglas Gregor via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 
>> On Jan 21, 2016, at 4:14 PM, Joe Groff <jgroff at apple.com <mailto:jgroff at apple.com>> wrote:
>> 
>> 
>>> On Jan 21, 2016, at 11:08 AM, Douglas Gregor via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> 
>>>> On Jan 20, 2016, at 8:41 PM, Rob Mayoff via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> 
>>>> On Wed, Jan 20, 2016 at 9:39 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> That said, I’m in favor of x.selector, or #selector(x).  The former seems more syntactically elegant if it is practical.
>>>> 
>>>> It seems like #selector(x) would make it easier to get good autocompletion (like Xcode's autocompletion of @selector(x) in ObjC doesn't insert argument placeholders).
>>> 
>>> I guess we could give more targeted code completions inside #selector(<code complete here>, only providing name completions for @objc entities.
>> 
>> We don't necessarily need to limit it to @objc entities; we can theoretically instantiate an ObjC method and selector for any method (or context-free closure, even) with an ObjC-compatible signature on demand.
> 
> Yes, we certainly could.
> 
> 	- Doug
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160121/e0eb0515/attachment.html>


More information about the swift-evolution mailing list