NSMutableDictionary

An NSMutableDictionary holds a mutable list of objects and their associated keys.

Example 1:
NSArray *letters;
letters = [[NSArray alloc]
  initWithObjects:@"A",@"B",@"C",nil];



NSMutableDictionary dict =
   [ NSMutableDictionary
   dictionaryWithCapacity:27 ];

for (int i=0; i<3; i++)
{
   NSString *letter =
     [letters objectAtIndex:i];
   NSMutableArray *nameList =
    [[NSMutableArray arrayWithCapacity:15]
     retain];
   [dict setObject:nameList
    forKey:letter];
}

NSString *theKey;
theKey = @"A";

// get the NSMutableArray for this key
NSMutableArray * theArray =
    [dict objectForKey:theKey];

// add the new object to the array
[theArray addObject:someObject];

// finally add it to the dict
[dict setObject:theArray forKey:theKey];


Example 2:




NSMutableDictionary dict =
   [ NSMutableDictionary
   dictionaryWithCapacity:27 ];

[dict setObject:@"Casa" forKey:@"House"]; [dict setObject:@"Gato" forKey:@"Cat"]; [dict setObject:@"Cabeza" forKey:@"Head"];


Useful methods:
  + dictionaryWithCapacity:
  - initWithCapacity:

   count
   allKeys
   objectForKey:
   setObject: forKey:
   removeObjectForKey:
   removeAllObjects

   - writeToFile:atomically:
   - writeToURL:atomically:
   - initWithContentsOfFile:
   - initWithContentsOfURL: