How to create Swift empty two dimensional array with size

前端 未结 5 1541

I try to do smth like this:

let myArray: [[MyClass]] = [5,5]

where [5,5] is size of array. I can\'t do this.

5条回答
  •  一生所求
    2020-12-28 19:41

    To add to the accepted answer, in Swift 3, the syntax is slightly different:

    var arr = [[Int]](repeating: [Int](repeating: 0, count: 5), count: 5)
    

    Note the order of arguments and repeating instead of repeatedValue.

提交回复
热议问题