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

The `final` modifier in Swift is a declaration attribute applied to a class property to explicitly prevent any subclass from overriding its implementation, including its getter, setter, or property observers.

Under the hood, the `final` modifier alters how the Swift runtime handles property resolution. By default, non-private properties in Swift classes utilize dynamic dispatch, requiring the runtime to consult a virtual method table (vtable) to resolve the correct property implementation. Applying the `final` modifier instructs the compiler to use static (direct) dispatch. This eliminates the vtable lookup overhead, allowing the compiler to inline the property access and optimize execution speed.

## Syntax and Application

The `final` keyword is placed immediately before the property declaration. It is applied to variable properties (`var`), encompassing both stored and computed properties.

While the compiler syntactically permits placing `final` before a constant (`let`) declaration, doing so is functionally redundant. Swift strictly prohibits overriding constant properties by definition, meaning `let` properties are inherently immune to subclass overrides without requiring the `final` modifier.

```swift theme={"dark"}
class BaseClass {
    // Final stored property
    final var identifier: String = "Base"
    
    // Final computed property
    final var description: String {
        return "Identifier is \(identifier)"
    }
    
    // Final property with observers
    final var state: Int = 0 {
        didSet {
            print("State changed to \(state)")
        }
    }
}
```

## Compiler Enforcement

The Swift compiler enforces the `final` restriction at compile time. Any attempt to use the `override` keyword on a `final` property in a subclass—even with syntactically valid override patterns like adding property observers or providing custom getters/setters—will immediately halt compilation and throw an error.

```swift theme={"dark"}
class SubClass: BaseClass {
    // ❌ Compiler Error: Var overrides a 'final' var
    override var identifier: String {
        get { return "Sub" }
        set { }
    }
    
    // ❌ Compiler Error: Var overrides a 'final' var
    override var state: Int {
        didSet {
            print("SubClass state changed")
        }
    }
}
```

## Scope and Limitations

* **Class-Bound:** The `final` modifier is only valid within `class` types. Because `struct` and `enum` types do not support inheritance, applying `final` to their properties is syntactically invalid and will result in a compiler error.
* **Protocol Exclusions:** You cannot apply `final` to property requirements within a `protocol` declaration, as protocols only define signatures, not implementations.
* **Class-Level Redundancy:** If an entire `class` is declared as `final` (e.g., `final class MyClass`), the class itself cannot be subclassed. Consequently, all properties within that class are implicitly final, making the addition of the `final` keyword to individual properties redundant.
* **Extensions:** Properties added to a class via an `extension` are implicitly final because Swift does not allow overriding declarations from extensions in subclasses (unless exposed to Objective-C via `@objc`).

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