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

# offset(from:to:)

Returns the number of UTF-16 characters between one text position and another text position.

```
func offset(from: UITextPosition, to toPosition: UITextPosition) -> Int
```

## Parameters

`from`

A custom object that represents a location within a document.

`toPosition`

A custom object that represents another location within document.

## Return Value

The number of UTF-16 characters between `fromPosition` and `toPosition`.

## Discussion

---

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)