iOS Programming Cookbook
上QQ阅读APP看书,第一时间看更新

Getting ready

Closures syntax in Swift is pretty easy and is easier than the syntax in C or Objective-C. The general form of closure is as follows:

{ (parameters) ->returnType in 
   // block of code goes here 
} 

As you see, you first put open curly braces, add list of parameters and the return type, then the keyword in, followed by lines of code in your closure. Closures are first-class type, which means it can be nested, passed in parameters, returned from function, and so on.