<!--
{
  "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/String/Comparator",
  "metadataVersion" : "0.1.0",
  "role" : "Structure",
  "symbol" : {
    "kind" : "Structure",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:SS10FoundationE10ComparatorV"
  },
  "title" : "String.Comparator"
}
-->

# String.Comparator

A `String` comparison performed using the given comparison options
and locale.

```
struct Comparator
```

## Topics

### Initializers

[`init(String.StandardComparator)`](/documentation/Swift/String/Comparator/init(_:))

Creates a `String.Comparator` that represents the same comparison
as the given `String.StandardComparator`.

[`init(options: String.CompareOptions, locale: Locale?, order: SortOrder)`](/documentation/Swift/String/Comparator/init(options:locale:order:))

Creates a `String.Comparator` with the given `CompareOptions` and
`Locale`.

### Instance Properties

[`let locale: Locale?`](/documentation/Swift/String/Comparator/locale)

The locale to use for comparison if the comparator is localized,
otherwise nil.

[`let options: String.CompareOptions`](/documentation/Swift/String/Comparator/options)

The options to use for comparison.

## Relationships

### Conforms To

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Equatable`](/documentation/Swift/Equatable)

[`Decodable`](/documentation/Swift/Decodable)

[`Encodable`](/documentation/Swift/Encodable)

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

[`Sendable`](/documentation/Swift/Sendable)

[`Hashable`](/documentation/Swift/Hashable)

---

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)