Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt

Use this file to discover all available pages before exploring further.

The >= (greater than or equal to) operator is a binary comparison operator that evaluates whether the left-hand operand is strictly greater than or equivalent to the right-hand operand, returning a Bool value.
lhs >= rhs

Protocol Conformance and Implementation

In Swift, the >= operator is governed by the Comparable protocol, which inherits from the Equatable protocol. To support the >= operator, a custom type must conform to Comparable.
static func >= (lhs: Self, rhs: Self) -> Bool
Swift’s standard library provides a default implementation for the >= operator for any type conforming to Comparable via a protocol extension. Because the protocol strictly requires explicit implementations only for the < (less than) and == (equal to) operators, the standard library extension provides >= by applying logical negation to the < operator. Under the hood, the default implementation evaluates lhs >= rhs as !(lhs < rhs).

Lexical Structure and Precedence

  • Precedence Group: ComparisonPrecedence
  • Associativity: none
Because the ComparisonPrecedence group is non-associative, the >= operator cannot be chained directly with other comparison operators in a single expression. An expression such as a >= b >= c will result in a compiler error, as the language cannot determine the grouping of the operands and the first evaluation would return a Bool, which cannot be compared against the third operand.

String and Collection Evaluation

When applied to String types, the >= operator performs a lexicographical comparison based on extended grapheme clusters. This ensures canonical equivalence, meaning strings are evaluated based on their linguistic meaning and visual representation (i.e., Character elements) rather than their underlying Unicode scalar compositions. Standard library collections such as Array, Set, and Dictionary do not conform to Comparable, even if their underlying elements do. Consequently, the >= operator cannot be applied to these collections; attempting to do so will result in a compiler error. To evaluate ordered collections sequentially, developers must bypass comparison operators and utilize methods such as lexicographicallyPrecedes(_:), provided the collection’s Element type conforms to Comparable (e.g., an Array of integers). This approach is strictly limited to ordered collections. It cannot be applied to Set or Dictionary because they are unordered collections with undefined iteration orders, making sequential comparison meaningless. Furthermore, calling lexicographicallyPrecedes(_:) on a Dictionary is invalid at the compiler level; the elements of a Dictionary are tuples ((key: Key, value: Value)), and tuples do not conform to Comparable in Swift.
Master Swift with Deep Grasping Methodology!Learn More