Swift Closures are defined as follows:
{ (parameters) -> return type in statements }
Thus, your sample code is considered closure by definition. However, I would rewrite it as follows, moving the return type into curly braces:
let triple = { (number: Int) -> Int in let result = 3 * number number return result } triple(1)
Parameters and the type of the return value begin after opening the curly bracket and end before the keyword, and the body of the closure begins after the keyword in and ends in the closing curly bracket. Further, I would recommend downloading and reading the iBook from iTunes, which can be found at the following address:
https://itunes.apple.com/us/book/swift-programming-language/id881256329?mt=11
Conrad taylor
source share