Multidimensional arrays in Swift

后端 未结 7 967
离开以前
离开以前 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 problem may have been due to a deficiency in an earlier version of Swift or of the Xcode Beta. Working with Xcode Version 6.0 (6A279r) on August 21, 2014, your code works as expected with this output:

    column: 0 row: 0 value:1.0
    column: 0 row: 1 value:4.0
    column: 0 row: 2 value:7.0
    column: 1 row: 0 value:2.0
    column: 1 row: 1 value:5.0
    column: 1 row: 2 value:8.0
    column: 2 row: 0 value:3.0
    column: 2 row: 1 value:6.0
    column: 2 row: 2 value:9.0
    

    I just copied and pasted your code into a Swift playground and defined two constants:

    let NumColumns = 3, NumRows = 3

提交回复
热议问题