S.P.
S.P.

Reputation: 5435

How to update NSMutableDictionary?

I have an NSMutableDictionary.

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

I have to update an element in that dictionary. How i can do that?

Upvotes: 9

Views: 26697

Answers (3)

Renetik
Renetik

Reputation: 6373

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.

Upvotes: 2

pedrotorres
pedrotorres

Reputation: 1232

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

Upvotes: 2

Mihir Mathuria
Mihir Mathuria

Reputation: 6539

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

Upvotes: 12

Related Questions