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;

Get Cocoa in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.