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

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

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

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

## Parameters

`textRange`

The range as an [`NSTextRange`](/documentation/AppKit/NSTextRange).

`type`

One of the available [`NSTextLayoutManager.SegmentType`](/documentation/AppKit/NSTextLayoutManager/SegmentType) values.

`options`

One or more of the [`NSTextLayoutManager.SegmentOptions`](/documentation/AppKit/NSTextLayoutManager/SegmentOptions) options.

`block`

A closure you provide to determine if the enumeration finishes early.

## 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.

---

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)