arrays - Swift appendContentsOf(顺序)

标签 arrays xcode swift

当我使用时:

  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/

相关文章:

c# - 将数组传递给 SQL Server 存储过程

c++ - 可视化多维数组如何放置在内存中的方法?

swift - 如何在按下通知操作时运行 URL?

xcode - 为什么 Xcode 的搜索导航器搜索错误的项目文件?

swift 3 : cut a hole in a SKSpriteNode

ios - 如何在 sks 文件 "SpriteKit action"中的 Xcode Action 编辑器上获取所有 Action 名称

php - MySQL PHP 将两行数据插入多维数组

arrays - 如何将看起来像数组值的字符串转换为数组?

ios - 如何在 SwiftUI 中设置 NavigationView 背景颜色

ios - AVCaptureVideoData输出分辨率