I have the following codes:
class ILProperty {
var value: T?
init(_ value: T) {
self.value = value
}
}
typealias ILStringProper
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.
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.
The last line in your code sample no longer gives a compile error, (since Swift 3). There is no mention of this in the Swift 3 Language Changes, so I can only assume that this was a bug.
As ganzogo mentioned it seems to be working fine with the latest Swift (3.0). Also, why do you declare a separate class to assign to the typealias
? I've tried this in a Playground and it seems ok:
class ILProperty<T> {
var value: T?
init(_ value: T) {
self.value = value
}
}
typealias ILStringProperty = ILProperty<String>
let x = ILStringProperty("X")