Multidimensional arrays in Swift

后端 未结 7 963
离开以前
离开以前 2020-11-30 22:43

Edit: As Adam Washington points out, as from Beta 6, this code works as is, so the question is no longer relevant.

I am trying to create and iterate through a two d

相关标签:
7条回答
  • 2020-11-30 23:12

    Your original logic for creating the matrix is indeed correct, and it even works in Swift 2. The problem is that in the print loop, you have the row and column variables reversed. If you change it to:

    for row in 0...2 {
      for column in 0...2 {
        print("column: \(column) row: \(row) value:\(array[column][row])")
    
      }
    }
    

    you will get the correct results. Hope this helps!

    0 讨论(0)
提交回复
热议问题