---
title: "compare(_:_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/sortcomparator/compare(_:_:)"
---

# compare(_:_:)

Provides the relative ordering of two elements based on the sort order of the comparator.

## Declaration

```swift
func compare(_ lhs: Self.Compared, _ rhs: Self.Compared) -> ComparisonResult
```

## Parameters

- `lhs`: The first element to compare.
- `rhs`: The second element to compare.

## Return Value

Return Value The relative ordering between the two elements according to the sort order of the comparator.

## See Also

### Using a Comparator

- [Compared](foundation/sortcomparator/compared.md)
