NSEnumerator

From GNUstepWiki
Revision as of 20:36, 3 April 2007 by Kendall (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSEnumerator.html#class$NSEnumerator

NSEnumerator in gnustep-base allow for iteration over collection.

Using NSEnumerator

The following example demonstrates the use of NSEnumerator with an NSArray object:

 NSArray *aArray = [NSArray arrayWithObjects: @"John", @"Bob", @"Jane"];
 NSEnumerator *enumerator = [aArray objectEnumerator];
 id obj;
 
 while(obj = [enumerator nextObject])
   doSomethingWithObject( obj );

Getting an NSEnumerator from a Collection

The NSArray, NSSet, and NSDictionary collection objects all include the -objectEnumerator method. NSDictionary also includes -keyEnumerator, which enumerates over the dictionary keys instead of the objects.