๐Ÿ”ธrequired initializer

โ•ฑ๐Ÿšง under construction -> subclass, override, designated initializer, inherited initializer, convenience init

swift โŸฉ type โŸฉ init โŸฉ initializers โŸฉ required

1๏ธโƒฃ write required before the definition of a class initializer to indicate that every subclass of the class must implement that initializer. ( ๐Ÿ‘‰ ๐Ÿ’ˆ็ฏ„ไพ‹ (1) )

2๏ธโƒฃ write required before every subclass implementation of a required initializer, donโ€™t write override when overriding a required designated initializer.

You donโ€™t have to provide an explicit implementation of a required initializer if you can satisfy the requirement with an inherited initializer. ( ๐Ÿ‘‰ ๐Ÿ’ˆ็ฏ„ไพ‹ (2) )

// superclass
class SuperClass {
    required init() { ... }    // 1๏ธโƒฃ required (designated) init
}

// subclass
class Subclass: SuperClass {
    required init() { ... }    // 2๏ธโƒฃ required init (No `override` hereโ—๏ธ)
}

Last updated