---
title: "enumerateTextSegments(in:type:options:using:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextlayoutmanager/enumeratetextsegments(in:type:options:using:)"
---

# enumerateTextSegments(in:type:options:using:)

Enumerates text segments of a specific type and in the text range you provide.

## Declaration

```swift
func enumerateTextSegments(in textRange: NSTextRange, type: NSTextLayoutManager.SegmentType, options: NSTextLayoutManager.SegmentOptions = [], using block: (NSTextRange?, CGRect, CGFloat, NSTextContainer) -> Bool)
```

## Parameters

- `textRange`: The range as an doc://com.apple.appkit/documentation/AppKit/NSTextRange.
- `type`: One of the available doc://com.apple.appkit/documentation/AppKit/NSTextLayoutManager/SegmentType values.
- `options`: One or more of the doc://com.apple.appkit/documentation/AppKit/NSTextLayoutManager/SegmentOptions options.
- `block`: A closure you provide to determine if the enumeration finishes early.

## Discussion

Discussion A text segment is a logically and visually contiguous portion of the text content inside a line fragment that you specify with a single text range. The framework enumerates the segments visually from left to right. Returning false breaks out of the enumeration.

## See Also

### Accessing the text storage

- [textContentManager](appkit/nstextlayoutmanager/textcontentmanager.md)
- [textContainer](appkit/nstextlayoutmanager/textcontainer.md)
- [textSelectionNavigation](appkit/nstextlayoutmanager/textselectionnavigation.md)
- [textSelections](appkit/nstextlayoutmanager/textselections.md)
- [usageBoundsForTextContainer](appkit/nstextlayoutmanager/usageboundsfortextcontainer.md)
- [replace(_:)](appkit/nstextlayoutmanager/replace(_:).md)
- [replaceContents(in:with:)](appkit/nstextlayoutmanager/replacecontents(in:with:)-2elb.md)
- [replaceContents(in:with:)](appkit/nstextlayoutmanager/replacecontents(in:with:)-80j0b.md)
