-
-
栈道莫见笑
2016-02-19
- qsort里面的参数到底应该怎么填呢?sorted我用不了
-
截图
0赞 · 0采集
-
-
大浓妆掩饰小悲伤
2016-01-03
- sorted(array,func)不仅可以传入一个函数,还可以传入一个闭包,sorted(array,{(a:Int,b:Int)->Bool in return a>b})
-
截图
0赞 · 0采集
-
-
胡子向右
2015-12-11
- 闭包的用法
-
截图
0赞 · 0采集
-
-
上树的猪
2015-12-01
- sorted(array,func)不仅可以传入一个函数,还可以传入一个闭包,sorted(array,{(a:Int,b:Int)->Bool in return a>b})
-
截图
0赞 · 1采集
-
-
康定雷歌
2015-09-30
- swift 俩值比较返回ture的话就会,前面的值会排在前面
-
0赞 · 0采集
-
-
康定雷歌
2015-09-30
- block 中排序细节, 返回ture, 前一个值排前面
-
0赞 · 0采集
-
-
luke_ron
2015-08-06
- var strArr = ["d","cd","bcd","abcd","abc","ab","a"]
sorted(strArr, {(s1:String,s2:String) -> Bool in
if count(s1) != count(s2)
{
return count(s1) < count(s2)
}
return s1 < s2
})
-
0赞 · 0采集
-
-
永远的零
2015-06-28
- 闭包
无函数名,只有函数体
{(s1:String, s2:String)->Bool in
return true
}
-
0赞 · 0采集
-
-
斌1991
2015-06-26
- 从Swift 1.2开始已经简化了countElements关键字为count,大家注意一下
var strArr = ["d","cd","bcd","abcd","abc","ab","a"]
sorted(strArr, {(s1:String,s2:String) -> Bool in
if count(s1) != count(s2)
{
return count(s1) < count(s2)
}
return s1 < s2
})
-
截图
0赞 · 3采集
-
-
beyonder1980
2015-06-09
- 闭包声明格式,与匿名函数类似:
sorted(arr,{(a:Int,b:Int)->Bool in
return a>b
})
从in开始写方法体。
-
截图
0赞 · 0采集
-
-
Shuai0001
2015-05-25
- 闭包:匿名函数 函数作为参数
-
截图
0赞 · 0采集
-
-
慕后端8796626
2015-04-21
- 闭包,无需声明的函数逻辑处理,一般用于仅需使用一次的函数 关键子 { in }
{(p1:T,p2:T)->ReturnType in
.....
.....
}
-
0赞 · 0采集
-
-
Eathon
2015-03-29
- 排序
闭包,无需声明的函数逻辑处理,一般用于仅需使用一次的函数
字符串长度比较,相等按字典序排列
-
截图
0赞 · 0采集
-
-
JanWilliem
2015-01-26
- var arr:[Int] = [1,3,5,7,9,2,4,6,8,0]
sorted(arr)
func compareTwoInts(a:Int,b:Int) ->Bool{
return a>b
}
sorted(arr,compareTwoInts) //不仅传一个函数,还能传闭包
//闭包和匿名函数有些像
sorted(arr,{(a:Int,b:Int)->Bool in
return a>b })
var strArr = ["d","cd","bcd","abcd","abc","ab","a"]
sorted(strArr,{(s1:String,s2:String) -> Bool in
if countElements(s1) != countElements(s2)
{
return countElements(s1) < countElements(s2)
}
return s1 < s2
})
-
1赞 · 1采集
-
-
爱赵晓羊
2015-01-08
- 闭包的函数体内容写法好诡异
声明输入参数
加 in
直接写函数体内容
-
截图
0赞 · 0采集
-
-
爱赵晓羊
2015-01-08
- 基本的闭包表示
-
截图
0赞 · 0采集
-
-
快到小利碗里来
2014-12-04
- 闭包和匿名函数有点像,有一个关键字in,
{(s1:String, s2:String) -> Bool in
if countElement(s1) != countElement(s2) {
return countElement(s1) < countElement(s2)
}
return s1 < s2
}
-
截图
1赞 · 1采集