語法: html
[html] view plaincopy閉包
{ (parameters) ->return type in statements} 函數
實例:採用函數實現:spa
[html] view plaincopy.net
let names =["Chris", "Alex", "Ewa", "Barry", "Daniella"] code
funcbackwards(s1: String, s2: String) -> Bool { orm
return s1 > s2 htm
} blog
var reversed = sort(names, backwards) 排序
println(reversed)
//sort 排序函數,backwards 經過排序規則的函數 採用閉包實現:
var reversed = sort(names, { (s1: String, s2: String) -> Bool in
return s1 > s2
})
println(reversed)
Swift交流討論論壇論壇:http://www.cocoagame.net
歡迎加入Swift技術交流羣:362298485