> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/ios/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/ios/swift/type/init/class/two-phase.md).

# 兩階段初始化

Two-Phase Initialization

## Implicit super.init()

If a subclass initializer:

* performs no customization in phase 2 of the initialization process&#x20;
* the superclass has a zero-argument designated initializer

you can omit a call to `super.init()` after assigning values to all of the subclass’s stored properties

{% tabs %}
{% tab title="Cat" %}

```swift
class Cat : Animal {

  override init() {
    print("Cat created")
    // super.init() implicitly called here. ⭐
  }

  override func makeNoise() {
    print("Mews")
  }
  
}
```

{% endtab %}

{% tab title="Animal" %}

```swift
class Animal {

  init() {
    print("Animal Created")
  }

  func makeNoise() {
    fatalError("Must Override to get specific Noise")
  }
  
}
```

{% endtab %}

{% tab title="main" %}

```swift
let cat = Cat()
cat.makeNoise()

// output:
// Cat created
// Animal created
// Mews
```

{% endtab %}
{% endtabs %}

:link: 原始碼：[repl.it](https://repl.it/@pegasusroe/implicit-superinit)
