[swift-evolution] Compiler directive for current closure reference
Taras Zakharko
taras.zakharko at uzh.ch
Mon Feb 22 12:20:30 CST 2016
Dear all,
I apologise in advance if this has already been suggested (or maybe even implemented), but its very difficult to keep track of the swift evolution list :)
We already have compiler directives like #line, #function. I would like to suggest a new directive #closure (name preliminary) that expands to the reference to the closure, function or method in whose body the directive occurs. Motivation: this will allow one to conveniently use design patterns like these:
addHandler({
guard stillRelevant() else {
removeHandler(#closure)
}
doSomething()
})
I am sure there are also other cases where such directive would come in handy.
More information about the swift-evolution
mailing list