Appending data to PLIST - iPhone

拜拜、爱过 提交于 2019-11-29 11:56:55

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.

You have a Dictionary to begin with,

124818240124810284.JPG //[valueForKey: 124818240124810284.JPG] 



                    item 0          String     Some Attribute 1 //[valueForKey:124818240124810284.JPG] valueForKey:Item 0];
                    item 1          String     Some Attribute 2 //[valueForKey:124818240124810284.JPG] valueForKey:Item 1];


    354273577823597297.JPG    //[valueForKey: 354273577823597297.JPG]    
                    item 0          String     Some Attribute 1 //[valueForKey: 354273577823597297.JPG] valueForKey:Item 0];
                    item 1          String     Some Attribute 2 //[valueForKey: 354273577823597297.JPG] valueForKey:Item 1;

And so on.....To add to it create a new dictionary with your new value/key pairs :

 NSMutableDictionary *newAttributes = [[NSMutableDictionary alloc]initWithObjectsAndKeys:@"Attribute 0",@"Item 0",nil];

Make a new dictionary:

   NSMutableDictionary *newEntry = [[NSMutableDictionary alloc]initWithObjectsAndKeys:newAttributes,@"xxxxx.jpg", nil];//Makes a new dictionary

Or to append the data to the existing dictionary:

[dictionaryToAppend setValue:newAttribues ForKey:xxxxx.jpg"];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!