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
thanks, very helpful
Or:
for( NSString *aKey in [bigUglyDictionary allKeys] )
{
// do something
}
Or somewhat faster:
for( NSString *aKey in bigUglyDictionary )
{
// do something
}
Or better yet, if your target OS supports blocks:
[bigUglyDictionary enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
// do something with key and obj
}];
you have got an ideal blog here! would you wish to make some invite posts on my weblog?