[swift-evolution] Type-safe selectors

Michel Fortin michel.fortin at michelf.ca
Fri Dec 4 17:01:50 CST 2015


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.


-- 
Michel Fortin
michel.fortin at michelf.ca
https://michelf.ca



More information about the swift-evolution mailing list