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

# compare(_:_:)

Provides the relative ordering of two items according to the ordering of the properties that the comparator’s key path references.

## Declaration

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

## Parameters

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

## Return Value

Return Value The relative ordering for the compared properties.

## Discussion

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