---
title: "compare(_:to:)"
framework: uikit
role: symbol
role_heading: Instance Method
path: "uikit/uitextinput/compare(_:to:)"
---

# compare(_:to:)

Returns how one text position compares to another text position.

## Declaration

```swift
func compare(_ position: UITextPosition, to other: UITextPosition) -> ComparisonResult
```

## Parameters

- `position`: A custom object that represents a location within a document.
- `other`: A custom object that represents another location within a document.

## Return Value

Return Value A value that indicates whether the two text positions are identical or whether one is before the other.

## See Also

### Evaluating text positions

- [offset(from:to:)](uikit/uitextinput/offset(from:to:).md)
