Swift generic superclass' init not accessible when constructing its subclass

前端 未结 4 2086
春和景丽
春和景丽 2021-01-01 18:48

I have the following codes:

class ILProperty {
    var value: T?
    init(_ value: T) {
        self.value = value
    }
}

typealias ILStringProper         


        
4条回答
  •  死守一世寂寞
    2021-01-01 19:23

    Here is another quote from Apple documentation

    Unlike subclasses in Objective-C, Swift subclasses do not inherit their superclass initializers by default. Swift’s approach prevents a situation in which a simple initializer from a superclass is inherited by a more specialized subclass and is used to create a new instance of the subclass that is not fully or correctly initialized.

    In the Swift Programming Language document from apple look section "Initializer Inheritance and Overriding".

    I do n understand your frustration but Swift's way of dealing with initializer is conceptually better.

提交回复
热议问题