TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
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
Thefinal 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.
Compiler Enforcement
The Swift compiler enforces thefinal 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.
Scope and Limitations
- Class-Bound: The
finalmodifier is only valid withinclasstypes. Becausestructandenumtypes do not support inheritance, applyingfinalto their properties is syntactically invalid and will result in a compiler error. - Protocol Exclusions: You cannot apply
finalto property requirements within aprotocoldeclaration, as protocols only define signatures, not implementations. - Class-Level Redundancy: If an entire
classis declared asfinal(e.g.,final class MyClass), the class itself cannot be subclassed. Consequently, all properties within that class are implicitly final, making the addition of thefinalkeyword to individual properties redundant. - Extensions: Properties added to a class via an
extensionare implicitly final because Swift does not allow overriding declarations from extensions in subclasses (unless exposed to Objective-C via@objc).
Master Swift with Deep Grasping Methodology!Learn More





