I am writing an iPhone game and have it working well with my level data hard coded but I would like to store the level data in a plist a load it at launch. I have never use
What you should do is create an NSDictionary
with all of the applicable data that you want, and read it from and write it to NSUserDefaults
.
Add your plist file as a resource file in your project. Say, it's name is config.plist
Get the path for the resource file. (Though, be careful of [NSBundle mainBundle] as it will not return the unit test bundle in a unit test.)
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
// this is autoreleased. you can retain it if needed NSArray *levelArray = [NSArray arrayWithContentsOfFile:plistPath];
NSDictionary *level = [levelArray objectAtIndex:i];
NSArray *seq = [level objectForKey:@"levelSequence"];
Hope it helps. Please note that I have not compiled the code, so there might be some typos.