Difference between revisions of "NSEnumerator"
Jump to navigation
Jump to search
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
− | http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSEnumerator.html#class$NSEnumerator | + | [http://www.gnustep.org/resources/documentation/Developer/Base/Reference/NSEnumerator.html#class$NSEnumerator NSEnumerator] in gnustep-base allow for iteration over collection. |
− | |||
− | NSEnumerator in gnustep-base allow for iteration over collection. | ||
== Using NSEnumerator == | == Using NSEnumerator == | ||
Line 7: | Line 5: | ||
The following example demonstrates the use of NSEnumerator with an [[NSArray]] object: | The following example demonstrates the use of NSEnumerator with an [[NSArray]] object: | ||
− | NSArray *aArray = [NSArray arrayWithObjects: @"John", @"Bob", @"Jane"]; | + | NSArray *aArray = [NSArray arrayWithObjects: @"John", @"Bob", @"Jane", nil]; |
NSEnumerator *enumerator = [aArray objectEnumerator]; | NSEnumerator *enumerator = [aArray objectEnumerator]; | ||
id obj; | id obj; |
Latest revision as of 06:28, 12 May 2009
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", nil]; 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.