In Swift, I am trying to create an array of 64 SKSpriteNode. I want first to initialize it empty, then I would put Sprites in the first 16 cells, and the last 16 cells (simulating an chess game).
From what I understood in the doc, I would have expect something like:
var sprites = SKSpriteNode()[64];
or
var sprites4 : SKSpriteNode[64];
But it doesn't work. In the second case, I get an error saying: "Fixed-length arrays are not yet supported". Can that be real? To me that sounds like a basic feature. I need to access the element directly by their index.
This question has already been answered, but for some extra information at the time of Swift 4:
In case of performance, you should reserve memory for the array, in case of dynamically creating it, such as adding elements with
Array.append()
.If you know the minimum amount of elements you'll add to it, but not the maximum amount, you should rather use
array.reserveCapacity(minimumCapacity: 64)
.