I have a plist that looks as below. Whats the preferred method to read a plist into and how do I read this into an array ? I can create a NSMutableDictionary, load the contents of this plist, load the keys into an Array and then use a for loop to read the top 2 keys – SomeData and MoreData. But I am unable to parse all the other keys (Key1, Key2 and Key3). How would I go about doing this ? Pasted code below that goes through the top 2 keys. (SomeData and MoreData). Thanks.
Plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SomeData</key>
<array>
<dict>
<key>Key1</key>
<false/>
<key>Key2</key>
<dict>
<key>Key3</key>
<integer>0</integer>
</dict>
</dict>
</array>
<key> MoreData</key>
</dict>
</plist>
Code:
-(IBAction)modifyPlist:(id)sender{
NSLog(@"Listing Keys");
NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithContentsOfFile:@"/Users/sureshb/Documents/myprogs/plistMod/com.test.plist"];
NSArray *keys = [dict allKeys];
for (NSString *key in keys){
NSLog(@"%@",key);
}
}
If I’m not mistaken you can access those values in next way: