---
title: "offset(from:to:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nstextelementprovider/offset(from:to:)"
---

# offset(from:to:)

Returns the offset between the two specified locations.

## Declaration

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

## Parameters

- `from`: A starting location.
- `to`: An ending location.

## Return Value

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

## Discussion

Discussion The return value could be positive or negative. This method can return NSNotFound 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).

## See Also

### Adjusting the range of the text element

- [adjustedRange(from:forEditingTextSelection:)](appkit/nstextelementprovider/adjustedrange(from:foreditingtextselection:).md)
