There is a new attribute in Swift 1.2 with closure parameters in functions, and as the documentation says:
This indicates that the parameter is only ever called (or passed as an @ noescape parameter in a call), which means that it cannot outlive the lifetime of the call.
In my understanding, before that, we could use [weak self]
to not let the closure to have a strong reference to e.g. its class, and self could be nil or the instance when the closure is executed, but now, @noescape
means that the closure will never be executed if the class is deinitalized. Am I understand it correctly?
And if I'm correct, why would I use a @noescape
closure insted of a regular function, when they behaves very similar?