> ## 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 Bitwise OR Assignment

The `|=` operator is the bitwise OR assignment operator in Swift. It is a compound assignment operator that performs a bitwise OR operation (`|`) between two integer operands and assigns the resulting value back to the left-hand operand.

```swift theme={"dark"}
lhs |= rhs
```

## Mechanics

The operator evaluates the binary representations of both operands. It compares the bits at each corresponding position and applies the following logic:

* If the bit in *either* the left-hand operand OR the right-hand operand is `1`, the resulting bit is set to `1`.
* If the bits in *both* operands are `0`, the resulting bit is set to `0`.

Because it is an assignment operator, the left-hand side (`lhs`) must be a mutable variable (`var`), while the right-hand side (`rhs`) can be a variable, constant, or literal.

## Syntax and Evaluation

```swift theme={"dark"}
var a: UInt8 = 0b0000_1100 // Decimal 12
let b: UInt8 = 0b0000_1010 // Decimal 10

a |= b 

// 'a' is mutated to 0b0000_1110 (Decimal 14)
```

**Bit-level execution:**

```text theme={"dark"}
  0000 1100  (lhs: 12)
| 0000 1010  (rhs: 10)

  0000 1110  (result: 14 assigned back to lhs)
```

## Type Constraints and Semantics

1. **Protocol Conformance:** Both operands must conform to the `BinaryInteger` protocol. This includes standard library integers (e.g., `Int`, `UInt8`, `Int64`) as well as custom arbitrary-precision integers. The operator cannot be applied to floating-point types.
2. **Strict Type Matching:** Swift enforces strict type safety. The `lhs` and `rhs` must be of the exact same integer type. Swift will not implicitly cast a `UInt8` to an `Int` to perform the operation; explicit initialization is required if the types differ.
3. **Evaluation Semantics:** The expression `a |= b` produces the same logical result as `a = a | b`, but with a critical distinction in evaluation: the compound assignment operator evaluates the left-hand side expression only *once*. This is highly relevant when the left-hand side is a computed property, a function returning an `inout` reference, or an array subscript.
4. **Thread Safety:** The `|=` operator performs a non-atomic read-modify-write sequence. It is not thread-safe and should not be treated as an atomic operation in concurrent contexts.

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