Appending data to PLIST - iPhone

前端 未结 2 2007
南笙
南笙 2020-12-20 04:10

we need to be able to read in the contents of an existing plist file then add to the array / dictionary then write this new data to the plist file. The stricture is simple.

2条回答
  •  死守一世寂寞
    2020-12-20 04:41

    You do it like this:

    // Get current content.
    NSDictionary *oldContent = [NSDictionary dictionaryWithContentsOfFile:plistPath];
    // Make a mutable copy.
    NSMutableDictionary *newContent = [[oldContent mutableCopy] autorelease];
    // Add new stuff.
    [newContent setObject:newObject forKey:newKey];
    // Now, write the plist:
    [newContent writeToFile:plistPath atomically:YES];
    

    There is no need to use NSPropertyListSerialization at all here.

提交回复
热议问题