1

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I get an other error: Undefined symbols: "_levelData", referenced from: _levelData$non_lazy_ptr in Game.o (maybe you meant: _levelData$non_lazy_ptr) ld: symbol(s) not found
You need to make sure that the .m/.c file where you define levelData is linked together with Game.o
1

Found the solution, i had a static initializer. You cant use those in combination with this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.