writeScoresXML

-(void)writeScoresXML{
 NSError *error;
 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //1
 NSString *documentsDirectory = [paths objectAtIndex:0]; //2
 NSString *path = [documentsDirectory stringByAppendingPathComponent:@"highScore.plist"]; //3
 
 NSFileManager *fileManager = [NSFileManager defaultManager];
 
 if (![fileManager fileExistsAtPath: path]) //4
 {
  NSString *bundle = [[NSBundle mainBundle] pathForResource:@"highScore" ofType:@"plist"];
  
  [fileManager copyItemAtPath:bundle toPath: path error:&error]; //6
 }
 
 HighScoreRecord *record1=[[HighScoreRecord alloc] init];
 [record1 setScore:[NSNumber numberWithInt:100]];
 [record1 setScoreDate:[NSDate date]];
 [record1 setScoreName:@"Me myself"];
 
 NSMutableData *data;
 NSKeyedArchiver *myArchiver=[[NSKeyedArchiver alloc] initForWritingWithMutableData:data];
 [myArchiver setOutputFormat:NSPropertyListXMLFormat_v1_0];
 [myArchiver encodeObject:record1 forKey:@"highScore"];
 [myArchiver finishEncoding];
 [data writeToFile:path atomically:YES];
  
 [data release];
 
}

 

http://www.iphonedevsdk.com/forum/iphone-sdk-development/50163-writing-out-object-plist.html

你可能感兴趣的:(Date,Path)