<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/ComparableComparator",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation20ComparableComparatorV"
  },
  "title" : "ComparableComparator"
}
-->

# ComparableComparator

A comparator that compares types according to their conformance to the comparable protocol.

```
struct ComparableComparator<Compared> where Compared : Comparable
```

## Overview

The comparator uses the relevant type’s <doc://com.apple.documentation/documentation/Swift/Comparable> implementation to compare instances.

## Topics

### Using a Comparator

[`compare(_:_:)`](/documentation/Foundation/ComparableComparator/compare(_:_:))

Provides the relative ordering of two elements.

### Inspecting a Comparator

[`order`](/documentation/Foundation/ComparableComparator/order)

The sort order that the comparator uses to compare.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)