且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swift Closures 中的 $0 和 $1 是什么意思?

更新时间:2022-04-11 23:53:18

$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
}