> ## 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 Static Property

A static property in Swift is a type-level property associated with the defining type itself, rather than with any individual instance of that type. Memory for a stored static property is allocated only once, meaning all instances of the type share the exact same underlying state and memory address.

## Declaration and Syntax

Static properties are declared using the `static` keyword. They can be implemented as either stored properties or computed properties within structures, classes, enumerations, and protocols.

```swift theme={"dark"}
struct NetworkConfiguration {
    // Stored static property
    static var maxConnections: Int = 10
    
    // Computed static property
    static var defaultTimeout: Double {
        return 30.0
    }
}
```

## Initialization and Memory Semantics

* **Lazy Initialization:** Stored static properties are inherently lazily initialized. Memory allocation and assignment do not occur until the exact moment the property is first accessed in the execution flow. The `lazy` modifier is neither required nor permitted.
* **Thread Safety:** The Swift runtime guarantees that the initialization of a stored static property is thread-safe. If multiple threads attempt to access an uninitialized static property simultaneously, the runtime ensures the initialization closure or assignment is executed exactly once.
* **Default Values:** Because types themselves do not possess initializers in the way instances do, stored static properties *must* be assigned a default value at the point of declaration.

## Accessing Static Properties

Static properties are accessed and mutated by querying the type directly using dot notation. They cannot be accessed through an instance of the type.

```swift theme={"dark"}
// Valid: Accessing via the type
let currentMax = NetworkConfiguration.maxConnections
NetworkConfiguration.maxConnections = 20

// Compiler Error: Cannot access via an instance
let config = NetworkConfiguration()
// let errorMax = config.maxConnections 
```

## `static` vs. `class` Modifiers

In the context of class types, Swift provides two distinct modifiers for type properties: `static` and `class`.

* `static`: Defines a type property that is statically dispatched. It cannot be overridden by subclasses. It is valid for both stored and computed properties.
* `class`: Defines a type property that is dynamically dispatched, allowing subclasses to override the implementation. The `class` modifier can only be applied to computed properties; Swift does not support stored `class` properties.

```swift theme={"dark"}
class BaseClass {
    // Statically dispatched; cannot be overridden
    static var staticProperty: String = "Base Static"
    
    // Dynamically dispatched; can be overridden
    class var classProperty: String {
        return "Base Class"
    }
}

class SubClass: BaseClass {
    // Compiler Error: Cannot override static var
    // override static var staticProperty: String = "Sub Static"
    
    // Valid override of a class property
    override class var classProperty: String {
        return "Sub Class"
    }
}
```

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