Swift generic superclass' init not accessible when constructing its subclass

前端 未结 4 2093
春和景丽
春和景丽 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:36

    From apple documentation:

    Swift provides a default initializer for any structure or base class that provides default values for all of its properties and does not provide at least one initializer itself. The default initializer simply creates a new instance with all of its properties set to their default values.

    Your class ilStringProperty is not a base class as it inherit from ILProperty so it must have an initializer, if you create one or override one does not matter since you have at least one initializer in your class as swift will not give one for free.

提交回复
热议问题