Iteration through NSDictionary could be achieved at least in two ways: using NSArray with [NSDictionary allKeys] or NSEnumerator.
Snippets:
NSArray *keyArray = [bigUglyDictionary allKeys];
int count = [keyArray count];
for (int i=0; i < count; i++) {
NSDictionary *tmp = [bigUglyDictionary objectForKey:[ keyArray objectAtIndex:i]];
}
NSEnumerator *enumerator = [bigUglyDictionary keyEnumerator];
id key;
while ((key = [enumerator nextObject])) {
NSDictionary *tmp = [bigUglyDictionary objectForKey:key];
}
Second way is a little bit faster, so if you work with huge dictionaries and have no need of array with their keys – use it.
Tags: iphone-dev, NSDictionary, NSEnumerator