What are Closures in Swift?

Closures are self contained blocks of functionality that can be passed around your code that can capture and store reference to any variables or constants from the context in which they are defined.

Closures can take one of the three following forms:

  1. Global functions that have a name but do not capture any values .
  2. Nested functions that have a name but capture values from surrounding context.
  3. Closure expressions are unnamed closures written in light-weight syntax that can capture and store reference from surrounding context.

Leave a Reply

%d bloggers like this: