You can enumerate the contents of a dictionary by key or by value using the NSEnumerator object returned by keyEnumerator and objectEnumerator respectively.
In other words:
NSEnumerator *enumerator = [myMutableDict keyEnumerator];
id aKey = nil;
while ( (aKey = [enumerator nextObject]) != nil) {
id value = [myMutableDict objectForKey:anObject];
NSLog(@"%@: %@", aKey, value);
}
Here is the version without object search. Notice that objectForKey calling not exist. They use keyEnumerator and objectEnumerator both.
Unless you need to use NSEnumerator, you can use fast enumeration (which is faster) and concise.
Also you can use an Enumerator with fast enumeration:
This is useful for things like doing the reverse enumerator in an array.
From the
NSDictionary
class reference:In other words: