Closure expression syntax in Swift

Closure expression syntax:

{ (parameters) -> <return type> in 

<statements to be executed>

}

  • The parameters of closure expression can be of any type such as tuples, in-out parameters, variadic parameters with a name.
  • The parameters cannot have a default value.
  • The in keyword indicates that the declaration pf parameters and return type pf closure expression is done and the closure body containing executable statements have begun.
  • The entire closure expression is contained inside a pair of curly braces { closure expression }.

 

Leave a Reply