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.

https://developer.apple.com/library/content/documentation/swift/conceptual/swift_programming_language/initialization.html

emphasis mine. designated initializers cannot call convenience initializers.

there diagram goes along rules demonstrate initializer "directions" allowed:

initializer chaining


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -