mercredi 9 octobre 2019

How to init a view controller with custom parameters using factory design pattern

I am trying to init a view controller with params using my ViewControllerFactory. The problem is that I don't know how many parameters will be pass and which type are they.

    func createViewController<VC: UIViewController>(storyboardId: String?,
                                                    vcType: UIViewController.Type,
                                                    vcID: String) -> VC? {

        if let storyboardId = storyboardId {
            let storyboard = UIStoryboard(name: storyboardId, bundle: .main)
            return storyboard.instantiateViewController(withIdentifier: vcID) as? VC
        } else {
            return vcType.init() as? VC
        }
    }

Some view controllers should be instantiated using parameters. How can I implement it using my factory? thanks

Aucun commentaire:

Enregistrer un commentaire