如何阅读一个plist

时间:2013-02-03 21:06:25

标签: ios objective-c if-statement plist

我是objective C的新手,我想阅读一个plist,而不是说该字符串是否具有此值并执行此操作。

我试过这个:

NSString *filePath = @"E/eg.plist";  
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] 
                                  initWithContentsOfFile:filePath];
NSString *value;value = [plistDict 
objectForKey:@"lang"];
if (NSString *value = @"1") {
     mySwitch3.on = YES;
}

1 个答案:

答案 0 :(得分:7)

这是获取给定键的值并将其与另一个字符串进行比较的方法。

NSMutableDictionary *plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
NSString *value = [plistDict objectForKey:@"lang"];
if ([value isEqualToString:@"1"]) {
    mySwitch3.on = YES;
}

有关Objective-C的更多信息:Learning Objective-C A Primer

Plist编程:PropertyLists