Reputation: 79
Im new to Objective-c, and what im trying to do is to create a 2 dimensional array of integers.
I know i can use C, in the following way:
int levelData[3][4] = {{1,1,1,1}, {1,0,0,1}, {1,1,1,1}};
Thing is, i want other other classes to be able to acces this data, so i have to include this variable in the header file, this is where the problem is:
declaring as int **levelData, int levelData[3][4]
or whatsoever doesnt work.
Can anyone help me?
Upvotes: 1
Views: 1174
Reputation: 79
Found the solution, i had a static initializer. You cant use those in combination with this.
Upvotes: 1
Reputation: 36082
in your .h file you write
extern int levelData[3][4];
in your .m/.c file you write
int levelData[3][4]= {{1,1,1,1},{1,0,0,1},{1,1,1,1}};
EDIT:
at any rate it is better to avoid global variables altogether and instead pass it as a parameter or have it is a ivar in your objective-c class. This avoids strange hard to see dependencies between modules e.g. if a function takes levelData as argument it is clear that the function operates on that argument however by having it global, you can't see easily what a function is using.
Upvotes: 2