我的Xcode项目中有一个像这样的.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>Steve</key>
<dict>
<key>married</key>
<true/>
<key>website</key>
<string>http://www.abc.com</string>
</dict>
<key>Bill</key>
<dict>
<key>website</key>
<string>http://www.cab.com</string>
<key>married</key>
<false/>
</dict>
</dict>
</plist>
所以现在我只想阅读网站,如果结婚是真的。上面的plist只是一个我知道它没有意义的例子。你能帮我么 ? :) 编辑我现在这样做:
if ([[dict objectForKey:@"married"] boolValue]) {
NSLog(@"(Y)");
}
但是,如果我为每一个词都做到这一点,它的工作量很大,我想我可以做得更容易,但我不知道如何做。
答案 0 :(得分:0)
我没有清楚地理解你的问题,但根据我的理解,我认为你希望为每个循环实现一个,所以这就是你如何能够立刻浏览整个plist:
NSMutableArray *arryaOfBools = [[NSMutableArray alloc] init];//To keep the values if you wnat
NSDictionary *dictioanry = [[NSDictionary alloc] init];// initialize your plist
// this for each will traverse through every dictionary present in the plist
for(NSDictionary * dict in dictioanry ){
/// you can do anything here as per your requirements
[arryaOfBools addObject:[dict valueForKey:@"married"]];
}
希望这能回答你的问题..
编辑:
以下是代码的解决方案
NSDictionary *senderDictionary = [NSDictionary dictionaryWithContentsOfFile:filePathforPlsit];
for(NSString *keyValue in senderDictionary){
[[senderDictionary valueForKey:keyValue] valueForKey:@"shortcut"];
}