<!--
{
  "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" : "Swift",
  "identifier" : "/documentation/Swift/MutableCollection/sort(using:)-9a05g",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SM10FoundationSkRzrlE4sort5usingyqd___tSTRd__AA14SortComparatorRd_0_7ElementQyd__Rsd_0_8ComparedQyd_0_AESTRtzr0_lF"
  },
  "title" : "sort(using:)"
}
-->

# sort(using:)

Sorts the collection using the given array of `SortComparator`s to
compare elements.

```
mutating func sort<S, Comparator>(using comparators: S) where S : Sequence, Comparator : SortComparator, Comparator == S.Element, Self.Element == Comparator.Compared
```

## Parameters

`comparators`

an array of comparators used to compare elements. The
first comparator specifies the primary comparator to be used in
sorting the sequence’s elements. Any subsequent comparators are used
to further refine the order of elements with equal values.

---

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)