Non-escaping closure

suggest change

In Swift 1 and 2, closure parameters were escaping by default. If you knew your closure wouldn’t escape the function body, you could mark the parameter with the @noescape attribute.

In Swift 3, it’s the other way around: closure parameters are non-escaping by default. If you intend the closure to escape the function, mark it with @escaping.

class ClassOne {
  // Non-escaping by default in Swift 3. No @noescape attribute is written.
  func methodOne(completion: () -> Void) {
    // 
  }
}

class ClassTwo {
  let obj = ClassOne()
  var greeting = "Hello, World!"

  func methodTwo() {
    obj.methodOne() {
      // A non-escaping closure may use self's members without writing self.
      print(greeting)
    }
  }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents