[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.





發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *