I want disable or remove some initialization from my super class, here my test codes:
class MyA {
init() {
}
init(value: String) {
}
init(value2: String) {
}
}
class MyB: MyA {
}
As you can see MyA has 3 initialization and MyB has the same because it is sub class, so I want remove 2 of this 3 initialization in MyB class, I want MyB just be initialize with init(), how can i do this? and the other 2 way be unavailable for sub class.
>Solution :
https://docs.swift.org/swift-book/LanguageGuide/Initialization.html
If your subclass doesn’t define any designated initializers, it automatically inherits all of its superclass designated initializers.
As such, define a designated initializer.
class MyB: MyA {
override init() {
super.init()
}
}