<!--
{
  "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/SortComparator",
  "metadataVersion" : "0.1.0",
  "role" : "Protocol",
  "symbol" : {
    "kind" : "Protocol",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "s:10Foundation14SortComparatorP"
  },
  "title" : "SortComparator"
}
-->

# SortComparator

A comparison algorithm for a specified type.

```
@preconcurrency protocol SortComparator<Compared> : Hashable, Sendable
```

## Overview

Objects that conform to [`SortComparator`](/documentation/Foundation/SortComparator) provide a comparison algorithm and storage for the sort order to use when comparing.

## Topics

### Inspecting a Comparator

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

The sort order that the comparator uses to compare.

[`localized`](/documentation/Foundation/SortComparator/localized)

A comparator that compares a string using a localized comparison in the current locale.

[`localizedStandard`](/documentation/Foundation/SortComparator/localizedStandard)

A comparator that compares a string using a localized, numeric comparison in the current locale.

### Using a Comparator

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

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

[`Compared`](/documentation/Foundation/SortComparator/Compared)

A type that the sort comparator can 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)
