<!--
{
  "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/UITextInput/textRange(from:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:objc(pl)UITextInput(im)textRangeFromPosition:toPosition:"
  },
  "title" : "textRange(from:to:)"
}
-->

# textRange(from:to:)

Returns the range between two text positions.

```
func textRange(from fromPosition: UITextPosition, to toPosition: UITextPosition) -> UITextRange?
```

## Parameters

`fromPosition`

An object that represents a location in a document.

`toPosition`

An object that represents another location in a document.

## Return Value

An object that represents the range between `fromPosition` and `toPosition`.

---

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)