Swift init Array with capacity

后端 未结 5 1115
执念已碎
执念已碎 2021-02-02 06:55

How do I initialize an Array in swift with a specific capacity?

I\'ve tried:

var grid = Array  ()
grid.reserveCapacity(16)
<
5条回答
  •  庸人自扰
    2021-02-02 08:01

    Swift 3 / Swift 4 / Swift 5

    var grid : [Square]?
    grid?.reserveCapacity(16)
    

    I believe it can be achieved in one line as well.

提交回复
热议问题