> ## 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.

# Swift Less Than

The `<` (less than) operator is a binary infix relational operator that evaluates whether the left-hand operand is strictly less in magnitude, value, or sorting order than the right-hand operand, returning a `Bool`.

In Swift, the `<` operator serves as the foundational requirement for the `Comparable` protocol. Because `Comparable` inherits from `Equatable`, any type that implements both the `<` and `==` operators automatically receives default implementations for the `>`, `<=`, and `>=` operators via protocol extensions provided by the Swift standard library.

## Syntax and Signature

The operator is defined as a static function within a type. The standard library signature requires both the left-hand side (`lhs`) and right-hand side (`rhs`) operands to be of the same type (`Self`):

```swift theme={"dark"}
static func < (lhs: Self, rhs: Self) -> Bool
```

## Precedence and Associativity

The `<` operator belongs to the `ComparisonPrecedence` group in Swift's parsing grammar.

* **Associativity:** `none`. Because it lacks associativity, chained comparisons like `a < b < c` are syntactically invalid in Swift. The compiler requires explicit logical conjunctions (e.g., `a < b && b < c`).
* **Higher Precedence:** Multiplication (`*`, `/`), addition (`+`, `-`), and nil-coalescing (`??`) operators belong to precedence groups that evaluate *before* comparison operators. This allows mathematical expressions to resolve prior to comparison (e.g., `a + b < c` evaluates as `(a + b) < c`).
* **Lower Precedence:** Logical operators (`&&`, `||`), the ternary operator (`?:`), and assignment operators (`=`) belong to precedence groups that evaluate *after* comparison operators. This allows chained logical checks to resolve correctly (e.g., `a < b && c < d` evaluates as `(a < b) && (c < d)`).

## Custom Implementation

When conforming a custom `struct`, `class`, or `enum` to `Comparable`, the `<` operator must be explicitly implemented as a `static` method if compiler synthesis is not available.

```swift theme={"dark"}
struct Vector: Comparable {
    let magnitude: Double
    
    static func < (lhs: Vector, rhs: Vector) -> Bool {
        return lhs.magnitude < rhs.magnitude
    }
}
```

## Compiler Synthesis

The Swift compiler can automatically synthesize the `<` operator implementation for specific types:

1. **Enumerations without associated values:** The compiler synthesizes `<` based on the semantic declaration order of the `case` statements (top-to-bottom).
2. **Enumerations with associated values:** The compiler synthesizes `<` if and only if all associated values themselves conform to `Comparable`. It evaluates the `case` declaration order first, and if the cases are identical, it evaluates the associated values lexicographically.

```swift theme={"dark"}
enum Status: Comparable {
    case idle
    case processing(Int)
    case completed
}
// Synthesis allows: Status.idle < Status.processing(1) -> true
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Swift Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
