Enumerate NSDictionary with keys and objects, PHP style

typeoneerror picture typeoneerror · Sep 23, 2010 · Viewed 26.8k times · Source

I know you can Enumerate the keys or values of NSMutableDictionary using NSEnumerator. Is it possible to do both together? I'm looking for something similar to the PHP foreach enumerator like:

foreach ($dictionary as $key => $value);

Answer

Sam picture Sam · Sep 23, 2010

Perhaps look into NSDictionary's method:

enumerateKeysAndObjectsUsingBlock:(void (^)(id key, id obj, BOOL *stop))

If you're not familiar with blocks in C/Objective-C, this is a good tutorial: http://thirdcog.eu/pwcblocks/