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

A class property is a type-level property associated with a class definition itself rather than with any specific instance of that class. In Swift, class properties are declared using the `class` keyword, which enables dynamic dispatch and allows subclasses to override the property's implementation.

## Technical Characteristics

* **Computed Only:** Swift restricts the `class` keyword to *computed* properties. You cannot declare a stored `class` property.
* **Overridability:** The primary mechanical distinction of a `class` property is that it permits subclass overriding.
* **Type-Level Access:** Class properties are accessed and mutated through the type name directly, or dynamically at runtime using the type of an instance.

## Syntax and Dynamic Dispatch

To declare an overridable type property, use the `class` modifier followed by `var` and a computed getter (and optionally a setter). Because `class` properties utilize dynamic dispatch, their overridden implementations can be resolved at runtime polymorphically.

```swift theme={"dark"}
class BaseClass {
    // A computed class property (Overridable)
    class var overridableProperty: String {
        return "Base Implementation"
    }
    
    // A method demonstrating polymorphic access
    func printProperty() {
        print(type(of: self).overridableProperty)
    }
}

class SubClass: BaseClass {
    // Overriding the computed class property
    override class var overridableProperty: String {
        return "Subclass Implementation"
    }
}

// Upcasting a SubClass instance to BaseClass
let instance: BaseClass = SubClass()

// Demonstrating dynamic dispatch via type(of:)
let dynamicValue = type(of: instance).overridableProperty 
// Evaluates to "Subclass Implementation"

// Demonstrating dynamic dispatch via internal type(of: self)
instance.printProperty() 
// Prints "Subclass Implementation"
```

## `class` vs. `static`

While both `class` and `static` define type properties, they dictate different dispatch mechanisms and storage capabilities:

1. **`class` Properties:** Utilize dynamic dispatch. They are strictly computed properties that subclasses can override.
2. **`static` Properties:** Utilize static dispatch. They can be either stored or computed properties. For *computed* properties, a `static` declaration is mechanically equivalent to a `final class` declaration, meaning it cannot be overridden by subclasses. However, this equivalence does not apply to stored properties, as the `class` keyword strictly prohibits stored properties, even when marked `final`.

## Memory and Initialization

Because `class` properties are strictly computed, they do not occupy persistent memory for state storage. They execute their defined getter and setter blocks upon access. If state storage is required at the type level within a class hierarchy, a `static` stored property must be used. Stored `static` properties are lazily initialized on their first access and are guaranteed by the Swift runtime to be thread-safe during initialization.

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