当我使用时:
func addResults(){
let myUniqueResult: [[String]] = []
//some work
var myResults = [[String]]()
//some work
myResults.appendContentsOf(myUniqueResult)
}
结果的输入顺序是否保持不变?
谢谢
最佳答案
由于数组是有序的集合类型,是的。
通过在 Playground 上粘贴这个来证明这一点
for _ in 0..<10000 {
var a = [1, 2, 3, 4, 5]
let b = [6, 7, 8, 9, 10]
a.appendContentsOf(b)
if a != [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] { fatalError("Wrong Order") }
}
关于arrays - Swift appendContentsOf(顺序),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35730331/