---
title: "compare(_:_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/comparablecomparator/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.

## Discussion

Discussion The method returns flipped comparisons if the sort order is SortOrder.reverse.
