[swift-evolution] Closure identity (was Re: Compiler directive for current closure reference)

Joe Groff jgroff at apple.com
Tue Feb 23 17:26:46 CST 2016


> On Feb 23, 2016, at 3:09 PM, Brent Royal-Gordon <brent at architechies.com <mailto:brent at architechies.com>> 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.

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.

-Joe

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160223/b11082a4/attachment.html>


More information about the swift-evolution mailing list