如何快速添加两个带有索引值的数组?

时间:2019-04-18 13:37:13

标签: swift

如果有两个这样迅速创建的数组:

var a:[String] = ["1", "2", "3"]

var b:[String] = ["A","B","C"]

如何将它们合并到[“ 1-A”,“ 2-B”,“ 3-C”]?

1 个答案:

答案 0 :(得分:2)

您可以尝试

let a = [1, 2, 3]
let b = ["A","B","C"]
let res = zip(a, b).map { "\($0)-\($1)" } 
print(res)