Swift Closures中$ 0和$ 1的含义是什么? [英] What does $0 and $1 mean in Swift Closures?
本文介绍了Swift Closures中$ 0和$ 1的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
let sortedNumbers = numbers.sort { $0 > $1 }
print(sortedNumbers)
任何人都可以解释, $ 0
和 $ 1
在swift中意味着什么?
Can anyone explain, what $0
and $1
means in swift?
更多样本
array.forEach {
actions.append($0)
}
推荐答案
$ 0
是传递给闭包的第一个参数。 $ 1
是第二个参数,等等。您显示的关闭是简写:
$0
is the first parameter passed into the closure. $1
is the second parameter, etc. That closure you showed is shorthand for:
let sortedNumbers = numbers.sort { (firstObject, secondObject) in
return firstObject > secondObject
}
这篇关于Swift Closures中$ 0和$ 1的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文