Friday, March 15, 2024
HomeiOS Developmentios - Swift Generic Varieties and Inheritance

ios – Swift Generic Varieties and Inheritance


I am creating an app for iOS and I’ve a operate in a view controller known as MainVC that has to return one other view controller. The view controller that this operate has to return inherits from one other view controller known as FatherVC. My downside is FatherVC has a generic sort, and that causes issues…

class MainVC: UIViewController{
    ...

    func returnOtherVC() -> //Right here I wish 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 need returnOtherVC() to return an occasion of Child1VC or Child2VC or Child3VC or different lessons like these. How can I pull this off?



Supply hyperlink

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments