[swift-evolution] Type-safe selectors

Joe Groff jgroff at apple.com
Fri Dec 4 17:16:48 CST 2015


> On Dec 4, 2015, at 3:01 PM, Michel Fortin <michel.fortin at michelf.ca> wrote:
> 
> Le 4 déc. 2015 à 17:26, Joe Groff <jgroff at apple.com> a écrit :
> 
>> This is a great approach, and it's mostly exactly what I've had in mind for this. Another nice thing about @convention(selector) is that the compiler could also context-free closures, like with @convention(c), by compiling them down to categories with mangled methods.
> 
> Something like this?
> 
> 	view.target = target
> 	view.action = { (target) in beep() }
> 
> Not bad, but wouldn't that be somewhat fragile? Given you must make sure the target is retained, I'm not sure it really make things simpler. And you need to make sure it's not nil either: this just won't work:
> 
> 	view.action = { beep() }
> 
> It looks like an error-prone idiom to me.

That shouldn't be a problem, since the function would be emitted with the same guaranteed-self convention ObjC methods normally have.

-Joe


More information about the swift-evolution mailing list