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

A `final` method in Swift is an instance or type method declared with the `final` modifier to explicitly prevent any subclass from overriding its implementation. Applying this modifier alters the method's resolution mechanism, instructing the Swift compiler to use static (direct) dispatch instead of dynamic (table) dispatch, completely bypassing the class's virtual method table (vtable).

## Syntax and Compiler Behavior

When a method is marked `final`, the compiler enforces strict inheritance rules. Any attempt to override the method in a subclass results in a compile-time error.

```swift theme={"dark"}
class BaseClass {
    // A standard method utilizing dynamic dispatch
    func standardMethod() {
        print("Base implementation")
    }
    
    // A final method utilizing static dispatch
    final func lockedMethod() {
        print("Final implementation")
    }
}

class DerivedClass: BaseClass {
    // Valid: Overriding a dynamically dispatched method
    override func standardMethod() {
        print("Derived implementation")
    }
    
    // COMPILER ERROR: Instance method overrides a 'final' instance method
    // override func lockedMethod() {
    //     print("Attempted override")
    // }
}
```

## Technical Characteristics

* **Dispatch Mechanism:** By default, Swift classes use dynamic dispatch for methods, requiring the runtime to look up the method's implementation in a vtable before executing it. The `final` keyword eliminates this overhead by emitting direct function calls. Instead of hardcoding absolute memory addresses, the compiler and linker resolve these direct calls using relative offsets, maintaining compatibility with modern Position Independent Code (PIC) and Address Space Layout Randomization (ASLR).
* **Compiler Optimization:** Because the compiler guarantees the method cannot be overridden, it can aggressively optimize the code. This includes inlining the method—replacing the function call entirely with the function's body—which reduces call-stack overhead.
* **Type Restriction:** The `final` modifier is exclusively applicable to reference types (`class`). Value types (`struct` and `enum`) do not support inheritance; therefore, their methods are inherently statically dispatched, rendering the `final` keyword syntactically invalid in those contexts.
* **Type Methods:** When applied to a type method (`class func`), the `final` modifier prevents subclasses from providing their own implementation. A `final class func` is functionally identical to a `static func`.

```swift theme={"dark"}
class Configuration {
    // Can be overridden by subclasses
    class func defaultSettings() {} 
    
    // Cannot be overridden; identical in behavior to 'static func'
    final class func coreSettings() {} 
}
```

* **Extension Behavior:** Native Swift does not support overriding methods declared in extensions. Methods declared within a class `extension` cannot be overridden by subclasses unless explicitly marked with the `@objc dynamic` modifiers, which forces the method to rely entirely on the Objective-C runtime for message passing. Without `@objc dynamic`, extension methods are implicitly statically dispatched. While functionally redundant, explicitly declaring these non-`@objc` extension methods as `final` is permitted by the compiler.

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