> ## 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 Multiplication Assignment

The `*=` (multiplication assignment) operator is a compound assignment operator that multiplies the value of the left-hand operand by the value of the right-hand operand, assigning the resulting product back to the left-hand operand.

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

While conceptually similar to `lhs = lhs * rhs`, `*=` is a distinct operator in Swift with its own function implementation. This design allows types to provide custom, optimized in-place mutation logic rather than relying on the compiler to automatically expand the expression.

## Underlying Implementation and Memory Model

In the Swift Standard Library, `*=` is defined as a static method requirement within the `Numeric` protocol:

```swift theme={"dark"}
static func *= (lhs: inout Self, rhs: Self)
```

The `inout` keyword on the `lhs` parameter dictates Swift's "copy-in copy-out" (call by value result) memory model. The value of the left operand is conceptually copied into the function, modified by the multiplication, and then reassigned back to the original variable upon the function's return. This reassignment mechanism is exactly why property observers, such as `didSet` and `willSet`, are triggered when using compound assignment operators on a property.

## Technical Characteristics

**Return Type**
Unlike C or Objective-C, compound assignment operators in Swift do not return the mutated value. The `*=` operator evaluates to `Void` (or `()`).

```swift theme={"dark"}
var a = 5
let b = 2
let result = (a *= b) // Compiles successfully, but `result` is inferred as `Void`
```

Because the operation evaluates to `Void`, it cannot be chained. Attempting an expression like `a *= b *= c` will result in a compile-time type mismatch, as the rightmost operation evaluates to `Void`, which cannot be multiplied with a numeric type.

**Mutability Requirement**
The left-hand operand (`lhs`) must be a mutable variable declared with `var`. Attempting to use `*=` on a constant (`let`) or an immutable property will result in a compile-time error.

**Type Constraints**
Both operands must evaluate to the same type, and that type must conform to the `Numeric` protocol (e.g., `Int`, `Double`, `Float`, `CGFloat`). Swift does not perform implicit type conversion; if the operands are of different numeric types, they must be explicitly cast prior to the operation.

**Overflow Behavior**
The overflow behavior of the `*=` operator depends strictly on the underlying data type:

* **Integer Types:** For types like `Int` or `UInt8`, Swift performs strict overflow checking. If the product exceeds the maximum or minimum representable bounds of the `lhs` data type, the program will trap and trigger a runtime crash to prevent silent data corruption.
* **Floating-Point Types:** For types like `Double`, `Float`, or `CGFloat`, the operator does not trap on overflow. Instead, it adheres to IEEE 754 semantics, evaluating to positive or negative infinity (`inf` or `-inf`) when the product exceeds the representable bounds.

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