Closure identity (was Re: Compiler directive for current closure reference)

(Joe Groff) #1

You get all these problems already if you have to hold on to the closure object to remove it—you have to track and manage the closure object; you can't use trailing closure syntax with `addObserver` if you have to first assign the closure somewhere else; you could accidentally share the closure; referencing the closure will keep all its captured state alive, even if the observed object goes away.



On Feb 23, 2016, at 3:09 PM, Brent Royal-Gordon < <>> wrote:

What is the better discriminator here? Sure, you could make Observer into a class that contains a closure, but how does that make anything better? It's an extra object to track and manage; it's an impediment to using trailing closure syntax with `addObserver`; it's more state you could accidentally share; it's additional memory and additional reference counting.