我想将以下数组合并,但是将其中的一个组合在另一个数组中。
数组1:
[Armor, Seal, Attack, Defend, Block]
数组2:
[9, 9, 3, 6, 3]
我希望整数将它们自己拼接到第一个数组上的逗号所在的位置。
示例:
[Armor 9, Seal 9, Attack 3, Defend 6, Block 3]
答案 0 :(得分:2)
在Swift 1.2中:
let arr1 = ["Armor", "Seal", "Attack", "Defend", "Block"]
let arr2 = [9, 9, 3, 6, 3]
let arr3 = Array(zip(arr1,arr2)).map {"\($0.0) \($0.1)"}
arr3 // ["Armor 9", "Seal 9", "Attack 3", "Defend 6", "Block 3"]