上QQ阅读APP看书,第一时间看更新
Map with dictionaries
We can also map over the (key, value) pairs of a dictionary:
let numbers = ["1": "one",
"2": "two",
"3": "three"]
let other = numbers.map({(key, val) in
(Int(key), val.uppercased())
})
This syntax takes a little getting used to; just remember, you need to create a tuple when reading the key and value of each dictionary element into the closure, and similarly return the new values as a tuple.