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

# NSTextSelectionNavigation

An interface you use to expose methods for obtaining results from actions performed on text selections.

```
class NSTextSelectionNavigation
```

## Topics

### Creating a selection navigation

[`init(dataSource: any NSTextSelectionDataSource)`](/documentation/UIKit/NSTextSelectionNavigation/init(dataSource:))

Creates a new object using the text selection data source you provide.

### Selection characteristics

[`var allowsNonContiguousRanges: Bool`](/documentation/UIKit/NSTextSelectionNavigation/allowsNonContiguousRanges)

Determines if the instance could produce selections with multiple noncontiguous selections.

[`var rotatesCoordinateSystemForLayoutOrientation: Bool`](/documentation/UIKit/NSTextSelectionNavigation/rotatesCoordinateSystemForLayoutOrientation)

Determines if the framework rotates the coordinate system to match the layout orientation.

[`struct Modifier`](/documentation/UIKit/NSTextSelectionNavigation/Modifier)

Values that describe how the framework handles different kinds of selection modifiers.

[`enum Destination`](/documentation/UIKit/NSTextSelectionNavigation/Destination)

Values that affect how the framework handles navigation across different textual boundaries during a selection.

[`enum Direction`](/documentation/UIKit/NSTextSelectionNavigation/Direction)

Values that describe the direction of a selection.

[`func textSelection(for: NSTextSelection.Granularity, enclosing: CGPoint, inContainerAt: any NSTextLocation) -> NSTextSelection?`](/documentation/UIKit/NSTextSelectionNavigation/textSelection(for:enclosing:inContainerAt:))

Returns a text selection that expands to the nearest boundaries for selection granularity and an enclosing point you specify.

### Accessing the data source

[`var textSelectionDataSource: (any NSTextSelectionDataSource)?`](/documentation/UIKit/NSTextSelectionNavigation/textSelectionDataSource)

The data source associated with this selection navigation.

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

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

### Working with text selections

[`func textSelection(for: NSTextSelection.Granularity, enclosing: NSTextSelection) -> NSTextSelection`](/documentation/UIKit/NSTextSelectionNavigation/textSelection(for:enclosing:))

Returns a text selection expanded to the nearest boundaries for the selection granularity and enclosing text selection text ranges you specify.

[`func textSelections(interactingAt: CGPoint, inContainerAt: any NSTextLocation, anchors: [NSTextSelection], modifiers: NSTextSelectionNavigation.Modifier, selecting: Bool, bounds: CGRect) -> [NSTextSelection]`](/documentation/UIKit/NSTextSelectionNavigation/textSelections(interactingAt:inContainerAt:anchors:modifiers:selecting:bounds:))

Returns an array of text selections produced by a tap or click at the point you specify.

[`func destinationSelection(for: NSTextSelection, direction: NSTextSelectionNavigation.Direction, destination: NSTextSelectionNavigation.Destination, extending: Bool, confined: Bool) -> NSTextSelection?`](/documentation/UIKit/NSTextSelectionNavigation/destinationSelection(for:direction:destination:extending:confined:))

Returns a new selection that results from applying the navigation operations you specify to the text selection you provide.

### Controlling cache behavior

[`func flushLayoutCache()`](/documentation/UIKit/NSTextSelectionNavigation/flushLayoutCache())

Flushes cached layout information.

### Finding the insertion point

[`func resolvedInsertionLocation(for: NSTextSelection, writingDirection: NSTextSelectionNavigation.WritingDirection) -> (any NSTextLocation)?`](/documentation/UIKit/NSTextSelectionNavigation/resolvedInsertionLocation(for:writingDirection:))

Returns the location for inserting the next input depending on the state of the current and secondary selections.

### Specifying deletion ranges

[`func deletionRanges(for: NSTextSelection, direction: NSTextSelectionNavigation.Direction, destination: NSTextSelectionNavigation.Destination, allowsDecomposition: Bool) -> [NSTextRange]`](/documentation/UIKit/NSTextSelectionNavigation/deletionRanges(for:direction:destination:allowsDecomposition:))

Returns the ranges for deleting the text based on the current selection and movement arguments.

## Relationships

### Conforms To

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

[`CustomStringConvertible`](/documentation/Swift/CustomStringConvertible)

[`CustomDebugStringConvertible`](/documentation/Swift/CustomDebugStringConvertible)

[`CVarArg`](/documentation/Swift/CVarArg)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

### Inherits From

[`NSObject-swift.class`](/documentation/ObjectiveC/NSObject-swift.class)

---

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)