<!--
{
  "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/NSTextSelectionDataSource",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextSelectionDataSource"
  },
  "title" : "NSTextSelectionDataSource"
}
-->

# NSTextSelectionDataSource

A set of methods that objects implement to provide data for, and manage text selections.

```
protocol NSTextSelectionDataSource : NSObjectProtocol
```

## Topics

### Range of the selection

[`documentRange`](/documentation/UIKit/NSTextSelectionDataSource/documentRange)

Returns the starting and ending locations for the document.

### Enumerating components of the selection

[`-  enumerateCaretOffsetsInLineFragmentAtLocation:usingBlock:`](/documentation/UIKit/NSTextSelectionDataSource/enumerateCaretOffsetsInLineFragment(at:using:))

Enumerates all the insertion point caret offsets from left to right in visual order.

[`-  enumerateContainerBoundariesFromLocation:reverse:usingBlock:`](/documentation/UIKit/NSTextSelectionDataSource/enumerateContainerBoundaries(from:reverse:using:))

Enumerates all the container boundaries starting from the location you specify.

[`-  enumerateSubstringsFromLocation:options:usingBlock:`](/documentation/UIKit/NSTextSelectionDataSource/enumerateSubstrings(from:options:using:))

Enumerates the textual segment boundaries starting at the location you specify.

### Finding specific content in the selection

[`-  locationFromLocation:withOffset:`](/documentation/UIKit/NSTextSelectionDataSource/location(_:offsetBy:))

Returns a new location using the location and offset you specify.

[`-  lineFragmentRangeForPoint:inContainerAtLocation:`](/documentation/UIKit/NSTextSelectionDataSource/lineFragmentRange(for:inContainerAt:))

Returns the range of the line fragment that contains the point you specify.

[`-  offsetFromLocation:toLocation:`](/documentation/UIKit/NSTextSelectionDataSource/offset(from:to:))

Returns the offset between the two locations you specify.

[`-  textRangeForSelectionGranularity:enclosingLocation:`](/documentation/UIKit/NSTextSelectionDataSource/textRange(for:enclosing:))

Returns a text range that corresponds to selection granularity of the enclosing location.

### Changing the characteristics of the selection

[`-  baseWritingDirectionAtLocation:`](/documentation/UIKit/NSTextSelectionDataSource/baseWritingDirection(at:))

Returns the base writing direction at the location you specify.

[`WritingDirection`](/documentation/UIKit/NSTextSelectionNavigation/WritingDirection)

Values that describe the writing direction inside a text selection.

[`-  textLayoutOrientationAtLocation:`](/documentation/UIKit/NSTextSelectionDataSource/textLayoutOrientation(at:))

Returns the layout orientation at the location you specify.

[`LayoutOrientation`](/documentation/UIKit/NSTextSelectionNavigation/LayoutOrientation)

Values that describe the possible layout orientations.

## Relationships

### Inherits From

[`NSObjectProtocol`](/documentation/ObjectiveC/NSObjectProtocol)

### Conforming Types

[`NSTextLayoutManager`](/documentation/UIKit/NSTextLayoutManager)

---

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)