i have declared my array like
var tile = [[Int]]()
and after that i have initialize its value like
for (var index = 0; in
As per comments you know that you are asking for value at index in an empty array. If you want to initialise the array you should try something like this:
for (var index = 0; index < 4; index++)
{
tile.append([])
for (var sindex = 0; sindex < 4; sindex++)
{
tile[index].append(sindex)
print("\(index) \(sindex)")
}
}
As the commentators @C_X & @MartinR say, your array is empty. Here's how to initialise it as you want...
var tile = [[Int]](count:4, repeatedValue: [Int](count: 4, repeatedValue: 0))
for index in 0 ..< 4 {
for sindex in 0 ..< 4 {
tile[index][sindex] = 0 // no error here now...
print("\(index) \(sindex)")
}
}
...of course, the for
loops are now redundant, if you just want zeroes!