I have an array of 6 NSNumber‘s in a file called level.m. In another file, game.m, I would like to ‘get’ this array and change each of its objects to separate integers.
I have tried using NSUserDefaults, but that seems to be a very awkward way of doing what I want to do. Is there a better way?
Yes, there is a much better way than using NSUserDefaults!
You can simply access the array directly from your game.m. First, you must import the level.h into the game.m (like so:
#import "level.h").Now say you want to int the value of the number at index 0 in your array. you can do that as follows:
int myNumber = [[[name_of_level_class name_of_array] objectAtIndex:0] intValue];A quick
NSLogwill prove that themyNumberinteger will be equal to whatever number you have at your 0 index in the array in your level.m