9

我有一个 NSMutableDictionary。

NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

我必须更新该字典中的一个元素。我怎么能这样做?

4

3 回答 3

12

请参考这里的API

首先使用检索对象

[dict objectForKey:@"key"];

稍后,您可以使用以下方法重新设置它们:

- (void)setObject:(id)anObject forKey:(id)aKey
- (void)setValue:(id)value forKey:(NSString *)key
于 2010-02-09T07:19:03.087 回答
2

NSMutableDictionary's method addEntriesFromDictionary.

https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMutableDictionary_Class/Reference/Reference.html

If both dictionaries contain the same key, the receiving dictionary’s previous value object for that key is sent a release message, and the new value object takes its place.

于 2013-01-26T14:45:04.793 回答
2

字典只允许您为每个键设置一个对象,因此如果您使用“为键设置对象”,它将更新当前对象

于 2012-11-09T14:31:32.950 回答