Generic Class Inheritance
suggest changeGeneric classes can be inherited:
// Models
class MyFirstModel {
}
class MySecondModel: MyFirstModel {
}
// Generic classes
class MyFirstGenericClass<T: MyFirstModel> {
func doSomethingWithModel(model: T) {
// Do something here
}
}
class MySecondGenericClass<T: MySecondModel>: MyFirstGenericClass<T> {
override func doSomethingWithModel(model: T) {
super.doSomethingWithModel(model: model) // Swift 3 and later; Swift 2 omitted this label
// Do more things here
}
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents