<!--
{
  "availability" : [
    "macOS: 12.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSTextElementProvider/offset(from:to:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(pl)NSTextElementProvider(im)offsetFromLocation:toLocation:"
  },
  "title" : "offset(from:to:)"
}
-->

# offset(from:to:)

Returns the offset between the two specified locations.

```
optional func offset(from: any NSTextLocation, to: any NSTextLocation) -> Int
```

## Parameters

`from`

A starting location.

`to`

An ending location.

## Return Value

An `Integer` that represents the offset between the starting and ending locations.

## Discussion

The return value could be positive or negative. This method can return <doc://com.apple.documentation/documentation/Foundation/NSNotFound-4qp9h> when the method can’t represent an offset as an integer value. This can occur, for example, if the locations aren’t in the same document).

---

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)