Swift闭包(Closure)
语法:
- { (parameters) ->return type in statements}
实例:采用函数实现:
- let names =["Chris", "Alex", "Ewa", "Barry", "Daniella"]
- funcbackwards(s1: String, s2: String) -> Bool {
- return s1 > s2
- }
- 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
相关推荐
yuwinter 2020-10-14
归去来兮 2020-09-18
Ericbig 2020-07-19
chaigang 2020-06-27
yogoma 2020-06-14
Andrewjdw 2020-05-27
jokerdby 2020-05-19
Kingonion 2020-04-23
ELEMENTS爱乐冬雨 2020-04-21
sunlizhen 2020-04-17
LczPtr 2020-04-14
Livis的开发之路 2020-03-11
Airuio 2020-03-06
Livis的开发之路 2020-02-28