How to create Swift empty two dimensional array with size

前端 未结 5 1589

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:35

    For two dimensional array with different dimension of each component (not square matrix) you may write

    var arr2D: [[Int]] = [Array(repeating: 1, count:2), Array(repeating: 2, count:3)]
    

提交回复
热议问题