This question already has answers here:
Swift equivalent to `[NSDictionary initWithObjects: forKeys:]`

(5个答案)


去年关闭。




我想结合2个数组。
arr1 = ["a", "b", "c"]
arr2 = ["1", "2", "3"]

我想使其成为:
"a" = "1"
"b" = "2"
"c" = "3"

因此,如果我将value“1”调用到label1,则意味着值“a”也像字典或索引一样被调用到label2。

最佳答案

就像这样:

let arr1 = ["a", "b", "c"]
let arr2 = ["1", "2", "3"]

let dictionary = Dictionary(uniqueKeysWithValues: zip(arr1, arr2))

关于ios - 将2数组合并为字典,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55609444/

10-12 22:57