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

A `final` class in Swift is a class declaration modified with the `final` keyword to explicitly prevent it from being inherited by any other class. Applying this modifier instructs the compiler to reject any attempt to subclass the entity, effectively sealing its inheritance hierarchy.

## Architectural Mechanics

By default, Swift classes utilize **dynamic dispatch**. When a method or property is accessed, the runtime consults a virtual method table (v-table) to determine the correct implementation to invoke. This mechanism is what enables polymorphism and method overriding.

When a class is marked `final`, the compiler guarantees that the class cannot be subclassed, meaning its methods and properties can never be overridden. Consequently, the Swift compiler optimizes the code by replacing dynamic dispatch with **static (direct) dispatch**. The compiler resolves the method calls at compile time, bypassing the v-table lookup entirely. This eliminates the runtime overhead associated with indirect calls and improves execution performance.

## Access Control and Module Boundaries

In Swift, the `final` keyword interacts closely with access control mechanics. A class marked `public` is already effectively "final" outside of its defining module; it can be instantiated by external modules but cannot be subclassed across module boundaries unless it is explicitly marked `open`. Therefore, the `final` keyword is specifically required to seal a class *within* its own module, or to explicitly seal `internal`, `fileprivate`, or `private` classes.

## Syntax and Compiler Enforcement

The `final` modifier precedes the `class` keyword. Access control modifiers can be placed between `final` and `class` (or before `final`), making declarations like `final public class` perfectly valid syntax.

```swift theme={"dark"}
final public class CoreEngine {
    var version: String = "1.0"
    
    func initialize() {
        // Initialization logic
    }
}
```

If another class attempts to inherit from a `final` class, the Swift compiler emits a fatal error during the compilation phase, preventing the code from building.

```swift theme={"dark"}
// Compiler Error: Inheritance from a final class 'CoreEngine'
class CustomEngine: CoreEngine {
    var customProperty: Int = 0
}
```

## Member-Level Finality

While marking an entire class as `final` implicitly finalizes all of its members, the `final` modifier can also be applied granularly to specific methods, properties, or subscripts within a non-final class. This prevents the overriding of those specific members while still allowing the class itself to be subclassed.

```swift theme={"dark"}
class BaseComponent {
    // Dynamically dispatched; can be overridden by subclasses
    func render() {
        print("Rendering base component")
    }
    
    // Statically dispatched; cannot be overridden
    final func calculateBounds() {
        print("Calculating fixed bounds")
    }
}

class CustomComponent: BaseComponent {
    // Valid override
    override func render() {
        print("Rendering custom component")
    }
    
    // Compiler Error: Instance method overrides a 'final' instance method
    override func calculateBounds() {
        print("Attempting to override fixed 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>
