2
我有20个词典在plist文件中。我需要用他们的名字编辑一个特定的词典,但是真的不知道如何做到这一点。 我需要获取值并对SearchCountry字典进行更改。如何在plist文件中编辑特定的NSDictionary?
如何编辑特定字典值?
我有20个词典在plist文件中。我需要用他们的名字编辑一个特定的词典,但是真的不知道如何做到这一点。 我需要获取值并对SearchCountry字典进行更改。如何在plist文件中编辑特定的NSDictionary?
如何编辑特定字典值?
得到一个子字典是这样的:
NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:plistFilename];
NSMutableDictionary *searchCountry = [plist objectForKey:@"SearchCountry"];
更改它的一个这样的价值观:
[searchCountry setValue:@"Cleveland" forKey:@"searchcity"];
保存如下:
BOOL success = [plist writeToFile:plistFilename atomically:YES];
尝试使用NSPorpertyListSerialization的财产名单上复杂的迭代。
否则,你可能试图访问特定字典使用下面的代码
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"yourPList"
ofType:@"plist"];
NSDictionary* plistDict = [NSDictionary dictionaryWithContentsOfFile:plistPath];
// plistDict contains all the dictionaries inside it now, you could try to access the particular inside the plistDict
id *searchKey = [plistDict objectForKey:@"SearchCountry"];
//OR
NSString* searchKeys = [plistDict valueForKeyPath:@"SearchCountry"];
它的工作就像魅力。谢谢丹 – GoCrazy 2013-03-26 00:12:46