I am programming a cocos2d game where, in most games, you must complete the level previous to proceed on to the next level. Each level is in a different layer (node). I wanted to store integers (1-20) to the property list so the variables are retained throughout the entire game. And yes i have been searching the internet for about an hour and cant find anything.
I found a code to store variables but I don’t know how to use it correctly.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentPath = [paths objectAtIndex:0];
NSString *path = [documentPath stringByAppendingPathComponent:@"levelscompleted.save"];
NSMutableDictionary* myDict = [[NSMutableDictionary alloc] init];
myDict = [NSKeyedUnarchiver unarchiveObjectWithFile:path];
NSString *nssLevelsCompleted = [myDict objectForKey:@"LevelsCompleted"];
LevelsCompleted = [nssLevelsCompleted intValue];
LevelsCompleted = 445;
[myDict setObject:nssLevelsCompleted forKey:@"LevelsCompleted"];
[NSKeyedArchiver archiveRootObject:myDict toFile:path];
Here is some sample code to get an idea (uses ARC for memory management):
Output: