我有一把带有多个键的plist。键的每个值都是“N”或“Y”。
我没有遇到任何问题并且更改值。但有没有办法将plist中的键的每个值更改为一个值?它会真正缩短我的代码。
当前代码更改plist中一个键的一个值,如下所示:
NSString *newValue;
newValue = @"Y";
[manufacturerDictionary setObject:[NSString stringWithString:newValue]
forKey:manufacturerName];
[manufacturerDictionary writeToFile: path atomically:YES];
[manufacturerDictionary release];
答案 0 :(得分:1)
根据您的代码,我假设您的plist包含一个归档的NSDictionary作为根对象。怎么样:
NSString *newValue = @"Y";
NSArray *allKeys = [manufacturerDictionary allKeys];
for (NSString *key in allKeys)
{
[manufacturerDictionary setObject:newValue forKey:key];
}
[manufacturerDictionary writeToFile:path atomically:YES];
[manufacturerDictionary release];
for (NSString *key in allKeys)
使用快速枚举来枚举字典中存在的每个键。