开发者

Write to Plist file, but dont replace it

开发者 https://www.devze.com 2023-03-25 02:15 出处:网络
Im creating a application that writes strings to a plist file, but the problem im having is every time its writing to the plist file, it deletes the previous one, im trying to figure out either how to

Im creating a application that writes strings to a plist file, but the problem im having is every time its writing to the plist file, it deletes the previous one, im trying to figure out either how to write to the existing one without deleting its original contents, or replace the plist file and keep the original contents and then re write them on to it..

Heres what my code looks like to save the file

 - (NSString *) saveFilePath
 {
NSArray *pathArray =
NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);

return [[pathArray objectAtIndex:0] stringByAppendingPathComponent:@"scores.plist"];

}

 -(void)alertView:(UIAlertView *)alert_view didDismissWithButtonIndex:  
(NSInteger)button_index{
if(button_index == 0){
    NSLog(@"1");
    score = 0;

}
if(button_index == 1){
    NSLog(@"2");

    NSString *scoreString = [NSString stringWithFormat:@"%i by %@", scor开发者_Go百科e, name.text];
    NSLog(@"%@", scoreString);
    NSArray *values = [[NSArray alloc] initWithObjects:scoreString, nil];
    [values writeToFile:[self saveFilePath] atomically:YES];
    [values release];

    score = 0;

}
}

Any ideas? Thanks!


You can read the plist and write it to the NSMutableArray. Then append it with your data and write it back to the file overwriting the existing one.

The same thing with NSMutableDictionary.

0

精彩评论

暂无评论...
验证码 换一张
取 消