<!--
{
  "availability" : [
    "iOS: 3.2.0 -",
    "iPadOS: 3.2.0 -",
    "macCatalyst: 13.1.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UITextRange",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(cs)UITextRange"
  },
  "title" : "UITextRange"
}
-->

# UITextRange

A range of characters in a text container with a starting index and an ending index in string backing a text-entry object.

```
@MainActor class UITextRange
```

## Overview

Classes that adopt the [`UITextInput`](/documentation/UIKit/UITextInput) protocol must create custom [`UITextRange`](/documentation/UIKit/UITextRange) objects for representing ranges within the text managed by the class. The starting and ending indexes of the range are represented by [`UITextPosition`](/documentation/UIKit/UITextPosition) objects. The text system uses both [`UITextRange`](/documentation/UIKit/UITextRange) and [`UITextPosition`](/documentation/UIKit/UITextPosition) objects for communicating text-layout information. There are two reasons for using objects for text ranges rather than primitive types such as <doc://com.apple.documentation/documentation/Foundation/NSRange-c.struct>:

- Some documents contain nested elements (for example, HTML tags and embedded objects) and you need to track both absolute position and position in the visible text.
- The WebKit framework requires that text indexes and offsets be represented by objects.

If you adopt the [`UITextInput`](/documentation/UIKit/UITextInput) protocol, you must create a custom [`UITextRange`](/documentation/UIKit/UITextRange) subclass as well as a custom [`UITextPosition`](/documentation/UIKit/UITextPosition) subclass.

## Topics

### Defining Ranges of Text

[`start`](/documentation/UIKit/UITextRange/start)

The start of a range of text.

[`end`](/documentation/UIKit/UITextRange/end)

The end of the range of text.

[`empty`](/documentation/UIKit/UITextRange/isEmpty)

A Boolean value that indicates whether the range of text represented by the receiver is zero-length.

## Relationships

### Conforms To

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

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

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

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

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

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

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

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