I'm creating an app for iOS and I have a function in a view controller called MainVC that has to return another view controller. The view controller that this function has to return inherits from another view controller called FatherVC. My problem is FatherVC has a generic type, and that causes problems...
class MainVC: UIViewController{
...
func returnOtherVC() -> //Here I want to return any class that inherits from FatherVC {
...
}
}
class FatherVC<T : AClass>{
...
}
class Child1VC: FatherVC<Class1>{ //Class1 inherits from AClass
...
}
class Child2VC: FatherVC<Class2>{ //Class2 inherits from AClass
...
}
class Child3VC: FatherVC<Class2>{ //Class3 inherits from AClass
...
}
I want returnOtherVC() to return an instance of Child1VC or Child2VC or Child3VC or other classes like these. How can I pull this off?
You are almost there, see the comments.