I want to save an high-score for local use only. A single int, that holds your highest score so i can test against it when a new score is made.
Would you recommend using the plist?
Something like:
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *finalPath = [path stringByAppendingPathComponent:@"Info.plist"];
NSDictionary *plistData = [[NSDictionary dictionaryWithContentsOfFile:finalPath] retain];
versionLabel = [[UILabel alloc] initWithFrame:CGRectMake(100,100,60,25)]; // for example
versionLabel.backgroundColor = [UIColor clearColor];
versionLabel.textColor = [UIColor whiteColor];
versionLabel.font = [UIFont systemFontOfSize:10];
NSString *versionString = [NSString stringWithFormat:@"v%@", [plistData objectForKey:@"CFBundleVersion"]];
versionLabel.text = versionString;
[self.view addSubview:versionLabel];
will this data be available the next time the app is opened?
The fastest and easiest thing to do, IMHO, would be to use NSUserDefaults. You get the speed of reading/writing to a plist, but you don’t need to deal with creating a whole new file just for a single value. The code for setting the high score would look like this..
Boom, that’s all you need. Then, when you next launch the app and want to check that high score, perhaps in a -(void)gameEnded method, or – (void)viewDidLoad, you just say
lastHighScore will now be the value stored in the user defaults, which you previously saved. Using setInteger:forKey: will overwrite the previous value if the key already exists.