Q:

2D Array Of Pointers in Objective C?

I am programming an iPhone game which has items laid out on a grid. Each item is represented by an object, and I want to use a 2D array to represent the contents of the grid. Since I will need to be passing the array through methods, I have attempted to declare it as:
MyClass*** grid;

and have a method to return it as:
-(MyClass ***) {
    return grid
}

But before even compiling i get this error:
Pointer to non-const type 'MyClass *' with no explicit ownership.

What does this mean, and why would it happen?

A:

When using Automatic Reference Counting you cannot have pointers to object pointers that way, since the owner will be unknown.
You can use nested NSArray objects instead, or switch to manual reference counting (you shouldn't do the latter if you already have a large project).

You could also instead have a method like this which the callee will call multiple times (once for each cell in the grid):
- (id)itemAtX:(NSUInteger)x y:(NSUInteger)y {
  // TODO: Add bounds checking.
  return grid[x][y];
}

