Instance Method

objectEnumerator

Returns an enumerator object that lets you access each object in the set.

Declaration

- (NSEnumerator<ObjectType> *)objectEnumerator;

Return Value

An enumerator object that lets you access each object in the set.

Discussion

The following code fragment illustrates how you can use this method.

NSEnumerator *enumerator = [mySet objectEnumerator];
id value;
 
while ((value = [enumerator nextObject])) {
    /* code that acts on the set’s values */
}

When this method is used with mutable subclasses of NSSet, your code shouldn’t modify the set during enumeration. If you intend to modify the set, use the allObjects method to create a “snapshot” of the set’s members. Enumerate the snapshot, but make your modifications to the original set.

Special Considerations

It is more efficient to use the fast enumeration protocol (see NSFastEnumeration). Fast enumeration is available in macOS 10.5 and later and iOS 2.0 and later.

See Also

Accessing Set Members

allObjects

An array containing the set’s members, or an empty array if the set has no members.

- anyObject

Returns one of the objects in the set, or nil if the set contains no objects.

- containsObject:

Returns a Boolean value that indicates whether a given object is present in the set.

- filteredSetUsingPredicate:

Evaluates a given predicate against each object in the receiving set and returns a new set containing the objects for which the predicate returns true.

- makeObjectsPerformSelector:

Sends a message specified by a given selector to each object in the set.

- makeObjectsPerformSelector:withObject:

Sends a message specified by a given selector to each object in the set.

- member:

Determines whether a given object is present in the set, and returns that object if it is.

- enumerateObjectsUsingBlock:

Executes a given block using each object in the set.

- enumerateObjectsWithOptions:usingBlock:

Executes a given block using each object in the set, using the specified enumeration options.

- objectsPassingTest:

Returns a set of object that pass a test in a given block.

- objectsWithOptions:passingTest:

Returns a set of object that pass a test in a given block, using the specified enumeration options.