-(void)writeToTopScorePlist<br>
{
<br>
NSError *error;<br>
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1<br>
NSString *documentsDirectory = [paths objectAtIndex:0]; //2<br>
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"TopScore.plist"]; //3<br>
NSFileManager *fileManager = [NSFileManager defaultManager];<br>
if (![fileManager fileExistsAtPath: path]) //4<br>
{<br>
NSString *bundle = [[NSBundle mainBundle] pathForResource:@"TopScore" ofType:@"plist"]; //5<br>
[fileManager copyItemAtPath:bundle toPath: path error:&error]; //6<br>
}<br>
NSMutableDictionary *data = [[NSMutableDictionary alloc] initWithContentsOfFile:path ];<br>
[data setObject:[NSString stringWithFormat:@"%i",self.MyTopScore] forKey:@"TopScore"];<br>
[data writeToFile:path atomically:YES];<br>
[data release] ;<br>
}
質問する
302 次
1 に答える
0
NSUserDefaults を使用します。
// Code used to save your highscore in the preference
int topscore = yourGameScore;
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:topscore] forKey:@"topscore"];
[[NSUserDefaults standardUserDefaults] synchronize];
// Code used to get your saved value from the prefs.
topScore = [[[NSUserDefaults standardUserDefaults] objectForKey:@"topscore"] intValue ];
于 2013-04-01T06:01:00.610 に答える