Subscribe to
Posts
Comments
NSLog(); Header Image

Iterators

Kuro5hin talks about iterators - C++, Java, etc. I didn't find any mention of Objective-C or Cocoa on the page, but I'd like to point out that the Cocoa frameworks have some pretty nice iterators and reverse iterators called "enumerators." Combined with some of the other methods, like componentsSeparatedByString: and so on, Cocoa's enumerators are quite nice. We use them quite frequently in MailDrop.

5 Responses to "Iterators"

  1. Cocoa's iterators are OK, but I've often wished they had:

    - (BOOL)hasNextObject;

    That combined with Obj-C's restrictions on where you can declare variables makes them kind of clumsy to use, IMO.

  2. Iterators

    Erik Barzeski posted about iterators in Cocoa, so I thought I’d give some perspectives from other languages. I think there are really two concepts here: iteration and generation. I don’t know that everyone agrees with these definitions, bu...

  3. That's not a restriction of Objective C, it's a restriction of C (which Objective C only extends).

    Apple's latest compiler (since Jaguar) uses C99, so you don't have to declare them at the beginning of a block any more.

  4. I want the enumerator and the object to be in the loop's scope. Does C99 let you declare like so:

    for ( int i = 0; i

  5. Nope, that's illegal even in C99 (don't know why).