Sign up for FlowVella
Sign up with FacebookAlready have an account? Sign in now
By registering you are agreeing to our
Terms of Service
Loading Flow
“Functions are actually a special case of closures”*
Type may be inferred by context. Single expressions closures may omit return
Parameter names can be shortened to $0, $1, etc. Operator functions can be even briefer
Closures
* Syntax diagram, sample code, and quote from Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/us/jEUH0.l
var names = ["Neil", "Tim", "Kiran"]
var reversed : [ String ]
reversed = sorted(names, { (s1: String, s2: String) -> Bool in
return s1 > s2
} )
reversed = sorted(names, { s1, s2 in s1 > s2 } )
reversed = sorted(names, { $0 > $1 } )
reversed = sorted(names, >)