以下是它的使用示例。
applyMutliplication(2,{$0 * 3}) array.map({$0 + 1})
谢谢!
来自Swift Book:
“Swift automatically provides shorthand argument names to inline closures,which can be used to refer to the values of the closure’s arguments by the names $0,$1,$2,and so on.” — Apple Inc. 07000
“Swift automatically provides shorthand argument names to inline closures,which can be used to refer to the values of the closure’s arguments by the names $0,$1,$2,and so on.”
— Apple Inc. 07000
它有助于减少代码的冗长(有时以牺牲可读性为代价),因此在定义闭包时不必编写长参数列表。