Escaping and Non-escaping Closures
Swift also allows you to use closures that cannot possibly create strong reference cycles.
This kind of closure, called a non-escaping closure, does not require you to explicitly refer to self.
Closures declared as function parameters are non-escaping by default.
Closures in other contexts, such as properties like netWorthChangedHandler, are escaping.
What does escaping mean? Escaping means that a closure passed to a function may be called after the function returns. That is, it escapes the scope of the function it is passed to. If a closure does not escape, the compiler knows that it cannot be called after the function returns, so no strong reference cycle is possible.
You can see this in action. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access