escaping closure and closure

 

Closures are self-contained blocks of functionality that can be passed around and used in your code.



let greeting:(String) -> () = { name in

    print("Hi, \(name)!")

}


birthday("Bebo")

 

  • An escaping closure is a closure that’s called after the function it was passed to returns. In other words, it outlives the function it was passed to.
  • non-escaping closure is a closure that’s called within the function it was passed into, i.e. before it returns.

Comments

Popular posts from this blog

iOS Questions (Swift Programming Language)

Dispatch techniques: Dynamic dispatch and Static Dispatch

What’s the difference between var and let? Which one would you choose for properties in a struct and Class why?