---
title: NSTextRange
framework: uikit
role: symbol
role_heading: Class
path: uikit/nstextrange
---

# NSTextRange

A class that represents a contiguous range between two locations inside document contents.

## Declaration

```swift
class NSTextRange
```

## Overview

Overview An NSTextRange consists of the starting and terminating locations. There the two basic properties: location and endLocation, respectively. The terminating location, endLocation, is directly following the last location in the range. For example, a location contains a range if (range.location <= location) && (location < range.endLocation) is true.

## Topics

### Creating a text range

- [init(location:)](uikit/nstextrange/init(location:).md)
- [init(location:end:)](uikit/nstextrange/init(location:end:).md)

### Characteristics of the text range

- [location](uikit/nstextrange/location.md)
- [endLocation](uikit/nstextrange/endlocation.md)
- [isEmpty](uikit/nstextrange/isempty.md)

### Comparing text ranges

- [intersection(_:)](uikit/nstextrange/intersection(_:).md)
- [intersects(_:)](uikit/nstextrange/intersects(_:).md)
- [isEqual(to:)](uikit/nstextrange/isequal(to:).md)
- [union(_:)](uikit/nstextrange/union(_:).md)

### Finding text within the text range

- [contains(_:)](uikit/nstextrange/contains(_:)-7hvi0.md)
- [contains(_:)](uikit/nstextrange/contains(_:)-5j4y2.md)

### Initializers

- [init(location:endLocation:)](uikit/nstextrange/init(location:endlocation:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Location and selection

- [NSTextSelection](uikit/nstextselection.md)
- [NSTextSelectionNavigation](uikit/nstextselectionnavigation.md)
- [NSTextLocation](uikit/nstextlocation.md)
