我有一个存储在plist中的字典数组。字典键是:globalKey和moneyKey。NSDictionary搜索关键字和更新值
现在我想搜索一个特定的键值的数组。如果键值存在,我需要用另一个键的新值更新词典。
示例:我需要在key @“globalKey”中搜索值5。如果值5存在,则需要使用key @“moneyKey”的新值更新该字典并将其保存到plist。
什么是最好的方法呢?
这是我如何添加新字典:
array = [NSMutableArray arrayWithContentsOfFile:filePath];
NSDictionary *newDict = [[NSDictionary alloc] init];
newDict = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithInt:month],@"globalKey", [NSNumber numberWithFloat:money], @"moneyKey", nil];
[array addObject:newDict];
[array writeToFile:filePath atomically:YES];
谢谢先生,您的回答非常好!只有一件小事是错误的。它应该是([myArray count])而不是([myArray count] - 1)。其他一切都很棒。 – maxus182
@ maxus182很高兴我能帮上忙!我已经更新了循环 - 我的错误是愚蠢的。 –