有什么快速的方法可以改变 NSDictionaries 的 NSArray 吗?我有一个很大的 NSArray,我想更新 NSDictionary 中特定键的值。有什么快速的方法可以改变内部字典以便我可以更新它们。
最佳答案
我猜你想同时修改所有的字典。如果你想修改它们,你的字典需要是 NSMutableDictionary
实例。
假设它们是,您可以使用 setValue:forKey:
同时修改所有这些。示例:
static NSMutableDictionary *dictionary() {
return [@{ @"first": @"Oscar", @"second": @"Meyer" } mutableCopy];
}
int main(int argc, const char * argv[])
{
@autoreleasepool {
NSArray *array = @[ dictionary(), dictionary(), dictionary() ];
[array setValue:@"Humphrey" forKey:@"first"];
NSLog(@"%@", array);
}
return 0;
}
关于ios - 在 NSArray 中改变 NSDictionary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21488718/