class - Why can't Swift initializers call convenience initializers on their superclass? -
consider 2 classes:
class { var x: int init(x: int) { self.x = x } convenience init() { self.init(x: 0) } } class b: { init() { super.init() // error: must call designated initializer of superclass 'a' } }
i don't see why isn't allowed. ultimately, each class's designated initializer called values need, why need repeat myself in b
's init
specifying default value x
again, when convenience init
in a
fine?
this rule 1 of "initializer chaining" rules specified in swift programming guide, reads:
rule 1: designated initializers must call designated initializer immediate superclass.
emphasis mine. designated initializers cannot call convenience initializers.
there diagram goes along rules demonstrate initializer "directions" allowed:
Comments
Post a Comment