Root ---- Array
Item 0 - Dictionary
fullName ---- String
Address ---- String
Paragraph 1 ---- Dictionary
fullName ---- String
Address ---- String
I have a plist that looks something like this. In the view, I have a button, when I click on it, I want to add a new "Item 2" or 3 or 4 or 5, etc. I just want to add some more names and addresses.
I spent 3 hours finding the perfect example, but came up with a short one. Sample Apple property lists were too deep. I saw code that probably comes close.
Many thanks
NSMutableDictionary *nameDictionary = [NSMutableDictionary dictionary]; [nameDictionary setValue:@"John Doe" forKey:@"fullName"]; [nameDictionary setValue:@"555 W 1st St" forKey:@"address"];
NSMutableArray *plist = [NSMutableArray arrayWithContentsOfFile:[self dataFilePath]]; [plist addObject:nameDictionary]; [plist writeToFile:[self dataFilePath] atomically:YES];
code>
- (NSString *)dataFilePath { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *path = [documentsDirectory stringByAppendingPathComponent:@"children.plist"]; return path; }
source share