O'Reilly logo

Cocoa in a Nutshell by James Duncan Davidson, Michael Beam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

NSEnumerator — Mac OS X 10.0

Synopsis

This class enumerates the contents of a collection. Instances of this class are created by the collection classes, generally with the method objectEnumerator. NSArray declares the method reverseObjectEnumerator, and NSDictionary declares keyEnumerator as additional methods that create instances of NSEnumerator.

To obtain the next object in an enumerator, we invoke the method nextObject. This will return an object, and advance the enumerator position forward in the collection. When the enumerator has exhausted the collection, nextObject returns nil. Enumerators cannot be reset; once you have enumerated a collection, you must obtain an new enumerator from the collection to start again. The method allObjects is used to return an NSArray of the objects that have not yet been enumerated. See Chapter 2 for more information on collections and enumerators.

image with no caption

@interface NSEnumerator : NSObject
                                  // Instance Methods
   - (NSArray *)allObjects;
   - (id)nextObject;

Subclasses

NSDirectoryEnumerator

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required