---
title: "enumerateTextLayoutFragments(from:options:using:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/nstextlayoutmanager/enumeratetextlayoutfragments(from:options:using:)"
---

# enumerateTextLayoutFragments(from:options:using:)

Enumerates the text layout fragments starting at the specified location.

## Declaration

```swift
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 doc://com.apple.uikit/documentation/UIKit/NSTextLayoutFragment/EnumerationOptions.
- `block`: A closure you provide that determines if the enumeration finishes early.

## Return Value

Return Value An NSTextLocation, or nil.

## Discussion

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.

## See Also

### Causing layout generation

- [textViewportLayoutController](uikit/nstextlayoutmanager/textviewportlayoutcontroller.md)
- [invalidateLayout(for:)](uikit/nstextlayoutmanager/invalidatelayout(for:).md)
- [textLayoutFragment(for:)](uikit/nstextlayoutmanager/textlayoutfragment(for:)-68dez.md)
- [textLayoutFragment(for:)](uikit/nstextlayoutmanager/textlayoutfragment(for:)-4dhrx.md)
- [ensureLayout(for:)](uikit/nstextlayoutmanager/ensurelayout(for:)-6ptsj.md)
- [ensureLayout(for:)](uikit/nstextlayoutmanager/ensurelayout(for:)-3duae.md)
- [NSTextLayoutManager.SegmentType](uikit/nstextlayoutmanager/segmenttype.md)
- [NSTextLayoutManager.SegmentOptions](uikit/nstextlayoutmanager/segmentoptions.md)
