-
-
-
-
-
- var names = ["Swift", "Arial", "Soga", "Donary"]
-
-
- func backwards(firstString: String, secondString: String) -> Bool {
- return firstString > secondString
- }
-
-
- var reversed = sort(nams, backwards)
-
-
-
-
-
-
- reversed = sort(names, { (firstString: String, secondString: String) -> Bool in
- return firstString > secondString
- })
-
-
- reversed = sort(names, { (firstString: String, secondString: String) -> Bool in return firstString > secondString})
-
- reversed = sort(names, { firstString, secondString in return firstString > secondString})
-
- reversed = sort(names, { firstString, secondString in firstString > secondString})
-
- reversed = sort(names, { $0 > $1 })
-
- reversed = sort(names, >)
-
-
- let strings = numbers.map {
- (var number) -> String in
- var output = ""
- while number > 0 {
- output = String(number % 10) + output
- number /= 10
- }
- return output
- }
-
- func increment(#amount: Int) -> (() -> Int) {
- var total = 0
- func incrementAmount() -> Int {
- total += amount
- return total
- }
- return incrementAmount
- }
-
- let incrementByTen = increment(amount: 10)
- incrementByTen()
- incrementByTen()
- incrementByTen()
-
- let incrementByOne = increment(amount: 1)
- incrementByOne()
- incrementByOne()
- incrementByTen()
- incrementByOne()
-
Swift学习之十四:闭包(Closures)
原文:http://www.cnblogs.com/Free-Thinker/p/4992826.html