一尘不染

如何在Swift中合并两个数组

swift

我有两个数组。

let A = ["91","91","49"]
let B = ["9989898909","9089890890","9098979896"]

我需要合并这些数组,并在下拉列表中显示为

["91 9989898909","91 9089890890","49 9098979896"]

我怎么能使用swift.im新手来快速获得此结果,有人可以帮忙吗?


阅读 1171

收藏
2020-07-07

共1个答案

一尘不染

压缩数组并连接结果:

let A=["91","91","49"]
let B=["9989898909","9089890890","9098979896"]
let zipped = zip(A, B)
let result = zipped.map { $0.0 + " " + $0.1 }
2020-07-07