Atanan bir başlatıcının ne olduğunu hatırlayalım.
belirlenmiş olan bir başlatıcı tam sınıfı ile ortaya tüm özelliklerini başlatır ve üst sınıf zincir başlatma işlemini devam etmek için, uygun bir üst sınıf başlatıcı çağırır.
alıntı Gönderen: Apple Inc. “The Swift Programming Language.”
class ClassA {
private let propertyA: Int
init(propertyA: Int) {
self.propertyA = propertyA
}
}
class ClassB: ClassA {
private let propertyB: Int
init(propertyA: Int, propertyB: Int) {
self.propertyB = propertyB
super.init(propertyA: propertyA)
}
}
extension ClassB {
// If this was a designated initializer, you need to initialize propertyB before calling a superclass initializer.
// But propertyB is a private property that you can't access.
// If you don't have the source code of ClassB, you will not even know there is a property called propertyB.
// This is why we can't use extensions to add designated initializers.
init(propertyC: Int) {
...
}
}