Skip to main content
A required initializer is a class initializer marked with the required modifier, enforcing a strict compiler contract that every direct and indirect subclass must implement that specific initializer.

Syntax and Implementation

To designate an initializer as required, place the required keyword before the init declaration in the superclass. When a subclass implements this initializer, it must also use the required keyword to propagate the requirement down the inheritance hierarchy. When a subclass implements a superclass’s already-required initializer, the override modifier is omitted.

Inheritance Rules

Subclasses do not always need to explicitly provide an implementation for a required initializer. If a subclass satisfies Swift’s rules for automatic initializer inheritance—specifically, by not defining any new designated initializers of its own—it will implicitly inherit the required initializer from its superclass.

Protocol Conformance

When a class conforms to a protocol that declares an initializer, the compiler mandates that the class implement that initializer with the required modifier. This guarantees that any future subclasses will also fulfill the protocol’s instantiation requirements.
The override and required Combination: If a subclass satisfies a protocol’s initializer requirement by overriding a non-required designated initializer from its superclass, both the required and override modifiers are mandatory.
Exception for Final Classes: If a class is marked with the final modifier, it cannot be subclassed. Therefore, when a final class implements a protocol’s initializer, the required keyword is omitted because the inheritance chain is terminated.
Tired of Poor Swift Skills? Fix That With Deep Grasping!Learn More