<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/NSTextElementProvider/enumerateTextElements(from:options:using:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextElementProvider(im)enumerateTextElementsFromLocation:options:usingBlock:"
  },
  "title" : "enumerateTextElements(from:options:using:)"
}
-->

# enumerateTextElements(from:options:using:)

Enumerates text elements starting at the text location you provide.

```
func enumerateTextElements(from textLocation: (any NSTextLocation)?, options: NSTextContentManager.EnumerationOptions = [], using block: (NSTextElement) -> Bool) -> (any NSTextLocation)?
```

## Parameters

`textLocation`

The [`NSTextLocation`](/documentation/UIKit/NSTextLocation) at which to start the enumeration.

`options`

One of the possible `NSTextElementProviderEnumerationOptions` directions.

`block`

A block you use to evaluate whether to continue the enumeration or tell the method to stop. Return `false` to end the enumeration process.

## Return Value

An `NSTextLocation`.

## Discussion

If `textLocation` is `nil`, the method uses `documentRange.location` for forward enumeration and `documentRange.endLocation` for reverse enumeration. When enumerating backward, the method starts with the element preceding the one containing `textLocation`. If enumerated at least one element, it returns the edge of the enumerated range.

The enumerated range might not match the range of the last element returned. It enumerates the elements in the sequence, but it can skip a range (it can limit the maximum number of text elements enumerated for a single invocation or hide some elements from the layout).

Returning `NO` or `false` from block breaks out of the enumeration.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)