<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextLayoutManager/enumerateTextLayoutFragments(from:options:using:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSTextLayoutManager(im)enumerateTextLayoutFragmentsFromLocation:options:usingBlock:"
  },
  "title" : "enumerateTextLayoutFragments(from:options:using:)"
}
-->

# enumerateTextLayoutFragments(from:options:using:)

Enumerates the text layout fragments starting at the specified location.

```
func enumerateTextLayoutFragments(from location: (any NSTextLocation)?, options: NSTextLayoutFragment.EnumerationOptions = [], using block: (NSTextLayoutFragment) -> Bool) -> (any NSTextLocation)?
```

## Parameters

`location`

The location where youstart the enumeration.

`options`

One or more of the available [`NSTextLayoutFragment.EnumerationOptions`](/documentation/AppKit/NSTextLayoutFragment/EnumerationOptions).

`block`

A closure you provide that determines if the enumeration finishes early.

## Return Value

An [`NSTextLocation`](/documentation/AppKit/NSTextLocation), or `nil`.

## Discussion

If `textLocation` is `nil`, the method starts at `self.textContentManager.documentRange.location`.The method uses `self.documentRange.endLocation` for reverse enumeration. When enumerating backward, it starts with the fragment preceding the one containing `textLocation`. If the method enumerates at least one fragment, 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. For example, it can limit the maximum number of text elements the method enumerates for a single invocation or hide some elements from the layout.

Returning `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)