This error occurs when the designated initializer of a subclass does not call the superclass's designated initializer using super.init.

In Swift, when you create a subclass, you must ensure that all properties of the superclass are initialized before the subclass can be used. This is done by calling the superclass's designated initializer using super.init within the subclass's designated initializer.

Here's an example to illustrate this:

class Superclass {
    var property: Int

    init(property: Int) {
        self.property = property
    }
}

class Subclass: Superclass {
    var additionalProperty: String

    init(property: Int, additionalProperty: String) {
        // Error: 'super.init' isn't called on all paths before returning from initializer
        self.additionalProperty = additionalProperty
    }
}

In the above example, the Subclass does not call super.init(property:) within its designated initializer. To fix this error, you need to call super.init(property:) before initializing any properties specific to the subclass:

class Subclass: Superclass {
    var additionalProperty: String

    init(property: Int, additionalProperty: String) {
        self.additionalProperty = additionalProperty
        super.init(property: property)
    }
}

By calling super.init(property:) before initializing additionalProperty, you ensure that all properties of the superclass are initialized before returning from the initializer

superinit isnt called on all paths before returning from initializer

原文地址: https://www.cveoy.top/t/topic/hFjS 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录