Reputation: 2285
<plist version="1.0">
<dict>
<key>accounts</key>
<array>
<dict>
<key>name</key>
<string>OLDNAME</string>
</dict>
</array>
</dict>
This is The plist File
Upvotes: 1
Views: 1159
Reputation: 5704
Maybe It will be too obviously but you can use following ways to modify it:
Ultimate solution for manipulating dictionaries stored in plists:
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@ "plist"];
NSDictionary *plistDictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath];
[plistDictionary setValue:@"newName" forKey:@"testKey"];
[plistDictionary writeToFile:plistPath atomically:YES];
Hope you will adopt this code sample for your own needs.
... Ok, I got it here is a code sample for your particular plist structure:
NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"yourPlist" ofType:@ "plist"];
NSMutableDictionary *plistDictionary = [[NSDictionary dictionaryWithContentsOfFile:plistPath] mutableCopy];
NSMutableArray *accountsArray = [(NSArray *)[plistDictionary valueForKey:@"accounts"] mutableCopy];
NSMutableDictionary *accountDictionary = [(NSDictionary *)[accountsArray objectAtIndex:0] mutableCopy];
[accountDictionary setValue:@"NewName" forKey:@"name"];
[accountsArray replaceObjectAtIndex:0 withObject:accountDictionary];
[plistDictionary setValue:accountsArray forKey:@"accounts"];
[plistDictionary writeToFile:plistPath atomically:YES];
Upvotes: 2
Reputation: 1129
Apple has plenty of docs on the topic.
Here is one that should help:
Upvotes: 0