O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSMutableDictionary — Mac OS X 10.0

Synopsis

NSDictionary, being an immutable class, does not allow clients to add, remove, or replace member objects after initialization. NSMutableDictionary, on the other hand, allows for the kinds of operations that alter the contents of the collection. Objects can be added to a mutable dictionary by invoking setObject:forKey:, and objects may be removed using removeObjectForKey:. When an object is added to a dictionary it is sent a retain message; when the object is removed, the dictionary will offset the retain with a release message.

NSMutableDictionary is toll-free bridged with the Core Foundation type CFDictionary. As such, NSMutableDictionary objects can be used interchangeably with the CFDictionary pointer type, CFDictionaryRef.

image with no caption

@interface NSMutableDictionary : NSDictionary
                                  // Initializers
   - (id)initWithCapacity:(unsigned)numItems;
                                  // Accessor Methods
   - (void)setObject:(id)anObject 
                                 forKey:(id)aKey;
   - (void)setDictionary:(NSDictionary *)otherDictionary;
                                  // Class Methods
   + (id)dictionaryWithCapacity:(unsigned)numItems;
                                  // Instance Methods
   - (void)addEntriesFromDictionary:(NSDictionary *)otherDictionary;
   - (void)removeAllObjects;
   - (void)removeObjectForKey:(id)aKey;
   - (void)removeObjectsForKeys:(NSArray *)keyArray;

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required