---
title: objectEnumerator()
framework: foundation
role: symbol
role_heading: Instance Method
path: foundation/nsset/objectenumerator()
---

# objectEnumerator()

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

## Declaration

```swift
func objectEnumerator() -> NSEnumerator
```

## Return Value

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

## Discussion

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

### Related Documentation

- [nextObject()](foundation/nsenumerator/nextobject().md)

### Accessing Set Members

- [allObjects](foundation/nsset/allobjects.md)
- [anyObject()](foundation/nsset/anyobject().md)
- [contains(_:)](foundation/nsset/contains(_:).md)
- [filtered(using:)](foundation/nsset/filtered(using:).md)
- [member(_:)](foundation/nsset/member(_:).md)
- [enumerateObjects(_:)](foundation/nsset/enumerateobjects(_:).md)
- [enumerateObjects(options:using:)](foundation/nsset/enumerateobjects(options:using:).md)
- [objects(passingTest:)](foundation/nsset/objects(passingtest:).md)
- [objects(options:passingTest:)](foundation/nsset/objects(options:passingtest:).md)
