I am working on an iphone app in objective-c and I am having trouble with making an array out of a class variable, for example…
I have a class named Cube and I am tryin to make an instance of this class named map that is an array
Cube map[10][10];
Xcode then says it is an error and suggests I do this
Cube *map[10][10];
When I do it this way though ^ I cannot access one of my methods I defined in the class Cube, now this is not ALL my methods, it is just one single method that wont work anytime I try to call it. The only thing different about this method than the others is that I pass a parameter to it. The Cube class declaration and definition both compile flawlessly.
Can anyone explain to me how to make a class with a 2 dimensional without turning it into a pointer. Also why does xcode recommend I make it a pointer, and why doesn’t the method work when I do it this way?
You probably want to use a Cocoa style array, i.e.
NSArrayorNSMutableArrayinstead of C-style array. It is much more flexible and is designed to work with Objective-c objects. Have a look at this simple tutorial on using a Cocoa array: http://iphonelearning.wordpress.com/2011/08/24/nsarray-and-nsmutablearray/.