I have this defined variable which is supposed to be a 2d array of ints. How can I make it so that the 2D array is 4x4 and the values are all 0?
var table: [[Int]]
You can use the Array.init(repeating:count:)
initializer.
Example:
let row = Array(repeating: 0, count: 4) // [0, 0, 0, 0]
var table = Array(repeating: row, count: 4)
Result:
print(table)
[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]