Wednesday, 18 September 2013

NSDictionary - (for id foo in dict) vs (for NSString *foo in [dict allKeys])

NSDictionary - (for id foo in dict) vs (for NSString *foo in [dict allKeys])

Suppose there is an NSDictionary *dict. What is the difference between the
following?
for (id key in dict) {
NSLog(@"value: %@", dict[key]);
}
for (NSString *key in [dict allKeys]) {
NSLog(@"value: %@", dict[key]);
}
I didn't know that the first version existed, and when I saw it I thought
it would be a compile-time error.

No comments:

Post a Comment