Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

North Bronson

macrumors 6502
Original poster
Oct 31, 2007
395
1
San José
I have an NSDictionary and I need to enumerate through the objects, but I don't need the keys. I see these two different ways:
Code:
    [myDictionary enumerateKeysAndObjectsUsingBlock: ^(id key, id object, BOOL *stop) {
        
        [object doSomething];
        
    }];
    
    [[myDictionary allValues] enumerateObjectsUsingBlock: ^(id object, NSUInteger index, BOOL *stop) {
        
        [object doSomething];
        
    }];
What's better here? Is it better to stick with the higher-level API that works directly on the dictionary, or tell the API that I'm going to treat the objects like an array?
 
Last edited:

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
If all you need are the objects, I'd probably just do:
Code:
for (id object in [myDictionary allValues])
That's even cleaner and easier to read (and 10.5 compatible ;)).
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.