1. 程式人生 > >[iOS] for each loop in objective c for accessing NSMutable dictionary

[iOS] for each loop in objective c for accessing NSMutable dictionary

如何瀏覽所有NSMutableDictionary 裡的內容?

NSMutableDictionary *xyz=[[NSMutableDictionary alloc] init];

解答:

for (NSString* key in xyz) {
    id value = [xyz objectForKey:key];
    // do stuff
}

This works for every class that conforms to the NSFastEnumeration protocol (available on 10.5+ and iOS), though NSDictionary

is one of the few collections which lets you enumerate keys instead of values. I suggest you read about fast enumeration in the Collections Programming Topic.

Oh, I should add however that you should NEVER modify a collection while enumerating through it.

from: