var myClosure = {
() -> Void in
println("My Closure")
}
myClosure()
//Console output:
My Closure
Closure with parameters
var myClosure2Times = {
(myNum: Int) -> Int in
return myNum * 2
}
println("2 * 10 = \(myClosure2Times(10))")
//Console output:
2 * 10 = 20
No comments:
Post a Comment