Phase 1 and Phase 2 initialization in Swift

Given 2 classes Foo and Bar where Bar is a subclass of Foo:

class Foo {
    var a: Int?
    var b: Int?

    init() {
        a = 1
    }
}

class Bar: Foo {
    var c: Int?

    override init() {
        super.init() // Phase 1

        // Phase 2: Additional customizations
        b = 2
        c = 3
    }
}

When you call Bar() it calls super.init() which the first line is to initialize the superclass which is Foo. So once Foo's properties are initialized completely, they can be set in Foo's initializer. This is represented by the a = 1 in the Foo initializer.

Once that is complete, phase 2 begins which is continuing the initialization of Bar following the super.init() line. This is where you can "perform additional customizations" either on the instance of bar or on its superclass. This is represented by b = 2 and c = 3.

let x = Bar()
x.a // 1
x.b // 2
x.c // 3