开发者

How to update NSMutableDictionary?

开发者 https://www.devze.com 2022-12-19 09:30 出处:网络
I have an NSMutableDictionary. NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];

I have an NSMutableDictionary.

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

I have to update an element in that diction开发者_运维技巧ary. How i can do that?


Please refer to the API here

First retrieve the objects using

[dict objectForKey:@"key"];

Later, you can set them back using:

- (void)setObject:(id)anObject forKey:(id)aKey
- (void)setValue:(id)value forKey:(NSString *)key


dictionary only allows you to have one objects for each key so if you use "set object for key" it will update the current one


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号