2013-02-03 158 views
1

我是objective C的新手,我想閱讀plist並且比如說字符串是否具有此值,請執行此操作。如何閱讀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; 
} 

回答

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