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

# compare(_:_:)

Provides the relative ordering of two elements.

## Declaration

```swift
func compare(_ lhs: Compared, _ rhs: 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.
