I have a method that is called addHighScore. When a user wants to quit the game, they can save their score out. In the resources folder, I created a highScore.plist and populated it with one entry. The structure is:
item 1 (array)
Name (dictionary, string)
Level (dictionary, string)
Score(dictionary, Number)
My problem is this: When I run this in the simulator, after I load the arrHighScores and then add the newScore dictionary, everything seems fine and the records get added (and shown via the NSLog statement) but this is ONLY as long as the app is running. Once I quit, go back in, the only entry that exists is the one I manually entered.
When I run this on the Device (iPhone), it never shows the records added, even while still in the game. I have looked at just about every example I can concerning NSDictionary and can't seem to figure out what is going wrong.
Any Ideas or suggestions are greatly appreciated. Thanks in advance for any and all help. (Geo...)
My method looks like this:
-(IBAction) addHighScore {
NSString *myPath = [[NSBundle mainBundle] pathForResource:@"highScores" ofType:@"plist"];
NSLog(@"myPath: %@", myPath);
NSMutableArray *arrHighScores = [[NSMutableArray alloc] initWithContentsOfFile:myPath];
NSMutableDictionary *newScore = [[NSMutableDictionary alloc] init];
[newScore setValue:@"Geo" forKey:@"Name"];
[newScore setValue:lblLevel.text forKey:@"Level"];
[newScore setValue:[NSNumber numberWithDouble: dblScore] forKey:@"Score"];
[arrHighScores addObject:newScore];
for (int i = 0; i < [arrHighScores count]; i++) {
NSLog(@"Retreiving (%d) --> %@", i, [arrHighScores objectAtIndex:i]);
}
[arrHighScores writeToFile:myPath atomically:YES];
NSMutableArray *tmpArray2 = [[NSMutableArray alloc] initWithContentsOfFile:myPath];
NSSortDescriptor *mySorter = [[NSSortDescriptor alloc] initWithKey:@"Score" ascending:YES];
[tmpArray2 sortUsingDescriptors:[NSArray arrayWithObject:mySorter]];
for (int i = 0; i < [tmpArray2 count]; i++) {
NSLog(@"Retreiving (%d) --> %@", i, [tmpArray2 objectAtIndex:i]);
}
[arrHighScores release];
[tmpArray2 release];
[mySorter release];
[newScore release];
}