nsenumerator

NSEnumerator performance vs for loop in Cocoa

I know that if you have a loop that modifies the count of the items in the loop, using the NSEnumerator on a set is the best way to make sure your code blows up, however I would like to understand the performance tradeoffs between the NSEnumerator class and just an old school for loop ...

How to use NSEnumerator with NSMutableDictionary?

How do I use NSEnumerator with NSMutableDictionary, to print out all the keys and values? Thanks! ...

Why doesn't NSEnumerator iterator recognize object properties within DrawRect?

I usually have no problems using NSEnumerator in the iPhone sdk but this is my first time using it within the DrawRect function of a UIView. The NSEnumerator iterator is causing an error: request for member "(member)" in something not a structure or union. 1) Why is this happening? 2) How can I workaround it? (P.S. the member not bei...

NSCFArray mutated while being enumerated - but I don't use enumerators

One thing I really don't like about Objective-C is that it's very difficult to find out what's going on under the hood. The latest problem this has caused me is a random exception that occurs in random places in my code and breaks everything - it's the one listed above, about concurrency problems with NSArray. The thing is that I never...

What is the value of NSEnumerator?

when for . . . in . . . is available? Specifically, when we can write: NSArray *array; // array allocated and initialized here. for (id obj in array) { // do something to the object here } Why would we ever use an NSEnumerator? ...

When is NSEnumerator finished?

How do we know when enumeration is finished? The docs say: the return value of nextObject is nil when all objects have been enumerated. I was hoping to implement some "delegate-like" behavior whereby ... if (nextObject == nil) { do something because we're done! } But I see there is no such thing as: enumerationDidFinish: ...

How do I get the index of the current Object in an NSEnumerator iteration?

Question: How do I get the index of the current Object in an NSEnumerator iteration? (I don't want to keep track of things using an integer counter or use a for loop due to speed reasons. I did it before I just cannot remember how I did it...) ...

Objective-C Iterating through an NSString to get characters

I have this function: void myFunc(NSString* data) { NSMutableArray *instrs = [[NSMutableArray alloc] initWithCapacity:[data length]]; for (int i=0; i < [data length]; i++) { unichar c = [data characterAtIndex:i]; [instrs addObject:c]; } NSEnumerator *e = [instrs objectEnumerator]; id inst; while (...