How do I append a new item to a plist?

前端 未结 3 733
难免孤独
难免孤独 2020-12-17 03:27

In my iPhone app, I have two plist files to store \"Themes\". One is a read-only file containing default themes, and one contains custom Themes that the user has created. I\

3条回答
  •  情歌与酒
    2020-12-17 03:59

    This is how I am appending data to the plist:

        NSString *filePath = [self dataFilePath];
    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) 
    {
        NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
        [array addObject:countdownLabel.text];
        [array writeToFile:[self dataFilePath] atomically:YES];
        [array release];
    }
    else
    {
        NSArray *array = [NSArray arrayWithObject:countdownLabel.text];
        [array writeToFile:filePath atomically:YES];
    }
    

提交回复
热议问题