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?
I think what you want is something like this:
for (id key in dictionary) {
NSLog(@"key: %@, value: %@", key, [dictionary objectForKey:key]);
}
Taken from here.
This is also a good choice if you like blocks.
[dict enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
}]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With