<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/Sequence/lexicographicallyPrecedes(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:STsSL7ElementRpzrlE25lexicographicallyPrecedesySbqd__STRd__AAQyd__ABRSlF"
  },
  "title" : "lexicographicallyPrecedes(_:)"
}
-->

# lexicographicallyPrecedes(_:)

Returns a Boolean value indicating whether the sequence precedes another
sequence in a lexicographical (dictionary) ordering, using the
less-than operator (`<`) to compare elements.

```
func lexicographicallyPrecedes<OtherSequence>(_ other: OtherSequence) -> Bool where OtherSequence : Sequence, Self.Element == OtherSequence.Element
```

## Parameters

`other`

A sequence to compare to this sequence.

## Return Value

`true` if this sequence precedes `other` in a dictionary
ordering; otherwise, `false`.

## Discussion

This example uses the `lexicographicallyPrecedes` method to test which
array of integers comes first in a lexicographical ordering.

```
let a = [1, 2, 2, 2]
let b = [1, 2, 3, 4]

print(a.lexicographicallyPrecedes(b))
// Prints "true"
print(b.lexicographicallyPrecedes(b))
// Prints "false"
```

> Note: This method implements the mathematical notion of lexicographical
> ordering, which has no connection to Unicode.  If you are sorting
> strings to present to the end user, use `String` APIs that
> perform localized comparison.

> Complexity: O(*m*), where *m* is the lesser of the length of the
> sequence and the length of `other`.

---

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)