我如何串联或雨燕合并数组? [英] How do I concatenate or merge arrays in Swift?
本文介绍了我如何串联或雨燕合并数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果有在迅速创造了这样两个数组:
If there are two arrays created in swift like this:
var a:[CGFloat] = [1, 2, 3]
var b:[CGFloat] = [4, 5, 6]
他们怎么可以合并到 [1,2,3,4,5,6]
?
推荐答案
您可以连接具有 +
阵列,构建一个新的数组
You can concatenate the arrays with +
, building a new array
let c = a + b
print(c) // [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
或追加一个阵列到另一个与 + =
(或延长
)
or append one array to the other with +=
(or extend
):
a += b
// Or:
a.extend(b) // Swift 1.2
a.appendContentsOf(b) // Swift 2
print(a) // [1.0, 2.0, 3.0, 4.0, 5.0, 6.0]
这篇关于我如何串联或雨燕合并数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文