Mac Developer Library

Developer

Foundation Framework Reference NSEnumerator Class Reference

Options
Deployment Target:

On This Page
Language:

NSEnumerator

NSEnumerator is an abstract class, instances of whose subclasses enumerate collections of other objects, such as arrays and dictionaries. More...

Inheritance


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.0 and later.
  • The array of unenumerated objects. (read-only)

    Declaration

    Swift

    var allObjects: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *allObjects

    Discussion

    This array contains all the remaining objects in the enumerated collection. It does not contain objects that have already been enumerated with previous nextObject messages.

    Accessing this property exhausts the enumerator’s collection so that subsequent invocations of nextObject return nil.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns the next object from the collection being enumerated.

    Declaration

    Swift

    func nextObject() -> AnyObject?

    Objective-C

    - (id)nextObject

    Return Value

    The next object from the collection being enumerated, or nil when all objects have been enumerated.

    Discussion

    The following code illustrates how this method works using an array:

    • NSArray *anArray = // ... ;
    • NSEnumerator *enumerator = [anArray objectEnumerator];
    • id object;
    • while ((object = [enumerator nextObject])) {
    • // do something with object...
    • }

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.