我有一个如下的plist文件。读取plist文件的首选方法是什么,我该如何将其读入数组中?我可以创建一个
NSMutableDictionary
,加载这个plist文件的内容,将键加载到一个数组中,然后使用一个for循环读取前两个键-SomeData
和MoreData
。但是我无法解析所有其他的键(Key1
、Key2
和Key3
)。我该怎么做呢?下面是经过粘贴的代码,它遍历了前两个键(SomeData
和MoreData
)。谢谢。
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>
代码:
-(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);
}
}