Iterators
Posted March 30th, 2003 @ 10:46am by Erik J. Barzeski
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.
Posted 30 Mar 2003 at 11:53am #
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.
Posted 30 Mar 2003 at 1:43pm #
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...
Posted 31 Mar 2003 at 9:31am #
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.
Posted 31 Mar 2003 at 3:27pm #
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
Posted 31 Mar 2003 at 3:38pm #
Nope, that's illegal even in C99 (don't know why).