objectEnumerator()
Returns an enumerator object that lets you access each object in the set.
Declaration
func objectEnumerator() -> NSEnumeratorReturn 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.