I have an NSMutableDictionary.
NSMutableDictionary* plistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
I have to update an element in that dictionary. How i can do that?
The NSMutableDictionary class declares the programmatic interface to objects that manage mutable associations of keys and values. It adds modification operations to the basic operations it inherits from NSDictionary . NSMutableDictionary is “toll-free bridged” with its Core Foundation counterpart, CFMutableDictionary .
NSDictionary creates static dictionaries, and NSMutableDictionary creates dynamic dictionaries. (For convenience, the term dictionary refers to any instance of one of these classes without specifying its exact class membership.) A key-value pair within a dictionary is called an entry.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With