I have created a multidimensional array, but as soon as I try to add values to it at specific indexes it crashes with an index out of range message. I think it has to do with the way I initialise the array - that I have to be more specific about what it can store etc. At this thread: Filling the Multidimensional Array in Swift it was suggested that I should initialise the array like this (obviously modified for my purposes):
var array: [[Int]] = Array(count:N, repeatedValue:Array(count:N, repeatedValue:0))
But I didn't get it to work, nor understood it properly. Below is the code I have. It crashes on the last code line.
var multiArray = [[Tile]]()
var gb = gameBoard.frame.width/4
for xItem in 0...3 { //DRAW TILE ON X AXIS
for yItem in 0...3 { //DRAW TILE ON Y AXIS
//CREATES A VARIABLE FOR TILE WITH PROPERTIES
tileView = Tile(frame: CGRect(x: (CGFloat(xItem) * gb), y: (CGFloat(yItem) * gb), width: gb, height: gb))
gameBoard.addSubview(tileView) //DRAWS TILE ONTO PARENT VIEW
multiArray[xItem][yItem] = tileView //CRASHES HERE WHEN TRYING TO ADD TO INDEX
}
}