【问题标题】:Swift appendContentsOf (order)Swift appendContentsOf(顺序)
【发布时间】:2016-03-01 18:14:40
【问题描述】:

当我使用时:

  func addResults(){
    let myUniqueResult: [[String]] = []
    //some work
    var myResults = [[String]]()
    //some work
    myResults.appendContentsOf(myUniqueResult)
}

结果的入场顺序保持不变?

谢谢

【问题讨论】:

  • 这是一个问题“结果的输入顺序保持不变吗?”它似乎更像是一种声明。你想弄清楚什么?

标签: arrays xcode swift


【解决方案1】:

由于数组是有序集合类型,是的

通过将其粘贴在操场上来证明这一点

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") }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多