views:

53

answers:

3

I have an NSDictionary and want to iterate over the objects. But at the same time, I need to know the key of the dictionary.

I remember there was a special, fancy form of fast enumeration, but have forgotten the exact syntax.

Anyone?

A: 
for (id key in mydictionary) {
   id mything = [mydictionary objectForKey:key];
}
Colin
+2  A: 

I think what you want is something like this:

for (id key in dictionary) {
    NSLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]);
}

Taken from here.

fbrereto
looks like the "normal form" of fast enumeration. same thing using an array returns an actual object. So this is actually really returning just the key, which then can be used to access the value? makes sense.
dontWatchMyProfile
A: 

keyEnumerator returns an object that lets you iterate through each of the keys in the dictionary. From here

sjobe