Browse Questions
  • @ViewBuilder is a result builder that lets you write multiple views inside a closure and have them composed into a single view.
  • A closure marked @escaping can outlive the function it was passed into — it "escapes" the function's scope.
  • Combine is Apple's reactive framework for processing asynchronous events over time.
  • All three transform collections but handle the results differently.

Answer: A closure marked @escaping can outlive the function it was passed into — it "escapes" the function's scope. Non-escaping closures are executed synchronously before the function returns.

Code Example:

// @escaping — stored and called later (e.g. async completion)
func fetchData(completion: @escaping (Result<Data, Error>) -> Void) {
    URLSession.shared.dataTask(with: url) { data, _, error in
        if let data = data {
            completion(.success(data))
        }
    }.resume()
}

// Non-escaping (default) — called inline, can be optimized by the compiler
func performOperation(action: () -> Void) {
    action() // called immediately, before function returns
}

Key Points:

  • Use @escaping for async callbacks, stored closures, delegate-style patterns
  • Non-escaping closures don't need self. to capture properties