> ## 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 Discardable Result Attribute

The `@discardableResult` attribute is a compiler directive applied to function, method, or initializer declarations to suppress the default compiler warning emitted when a caller invokes the function without capturing or utilizing its return value.

By default, Swift enforces strict return value utilization through static analysis. If a function returns a value, the compiler expects the caller to assign it to a variable, evaluate it in an expression, or explicitly discard it using the wildcard pattern (`_ =`). Applying `@discardableResult` alters this behavior for the decorated declaration, signaling to the compiler that ignoring the return value is an intended operation, thereby silencing the `unused-result` warning.

## Syntax

The attribute is placed immediately preceding the `func` or `init` keyword.

```swift theme={"dark"}
@discardableResult
func computeAndCache() -> Int {
    let calculatedValue = 42
    // Internal state mutation or caching logic
    return calculatedValue
}

// Caller behavior
computeAndCache()               // Valid: No compiler warning generated
let result = computeAndCache()  // Valid: Return value remains fully accessible
```

## Technical Characteristics

* **Compile-Time Only:** The attribute strictly affects compile-time static analysis. It does not alter the runtime behavior, memory allocation, or the actual return type of the function.
* **Caller Flexibility:** It provides the caller with the option to either capture the returned data or safely ignore it without requiring the explicit `_ = functionCall()` syntax.
* **Redundancy:** Applying `@discardableResult` to a function that returns `Void` (or `()`) is redundant, as the Swift compiler inherently permits `Void` return values to be implicitly discarded.
* **Protocol Conformance:** When applied to a method requirement within a `protocol`, the attribute dictates the compiler behavior for any type calling the method through the protocol interface. Conforming types can also independently apply the attribute to their specific implementations.

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