← Home

What does @escaping do?

One of the things Xcode suggests most is whether a closure should take @escaping. Because Xcode suggests it, people rarely dig into what @escaping actually does.

If a closure is not @escaping, it must be called before the function returns; that is, it can’t be used inside async responses. If @escaping is used, the closure is retained in memory and can be called after the function returns, inside an async response. In short: if the closure will outlive the function, you need @escaping.