📜  快速地图代码示例

📅  最后修改于: 2022-03-11 15:01:01.832000             🧑  作者: Mango

代码示例1
// A map example which maps each item in  this array of numbers
// to its value multiplied by 2.

let array = [1, 2, 3, 4]

// Full closure
print(array.map({ (num: Int) -> Int in return num * 2 }))

// Abbreviated trailing closure, with inferred arguments, 
// argument type, and return type.
print(array.map { $0 * 2 })

// Output: [2, 4, 6, 8]