NSDictionary

Dok-tips for Foundation class NSDictionary

Characteristics

A key-value pair type object

All keys and objects are held strongly

New syntax for creating instances inline using @{ }

NSDictionary * colors =  @{ @"blue" : [UIColor blueColor],  ...};

Immutable

Examples

NSString * keyString = @"myKey";
UIColor * aColorObject = arrayOfColorObjects[myKey];

Keys must implement hash: and isEqual: properly (NSString does - NSObject does not since its hash is the pointer like memory address and its comparison is ==).

When the key is of a valid class type (hash: and isEqual:), then it can be used as an argument to the NSDictionary's method:

- (id)objectForKey:(id)key;

List of all foundation classes