Friday, August 19, 2022
HomeiOS Developmentios - How shall I instantiate a generic ViewController. It's not being...

ios – How shall I instantiate a generic ViewController. It’s not being instantiated

class FindFalconeVC<ViewModel: FindFalconeVCViewModelProtocol>: UIViewController {

    var viewModel: ViewModel!

    init(viewmodel: ViewModel) {
        self.viewModel = viewmodel
        tremendous.init(nibName: nil, bundle: nil)

    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been carried out")

    override func viewDidLoad() {
        // Do any further setup after loading the view.

protocol FindFalconeVCViewModelProtocol: ObservableObject {

    var rockets: [Rocket] {get set}
    var planets: [Planet] {get set}
    var webservice: FindFalconVCServicesProtocol {get set}

    func getPlanetsList() async -> [Planet]?
    func getRocketsList() async -> [Rocket]?
    func findFalcon() async -> End result<String, ServiceError>
    func populateData() async 

After which inside “willConnectTo session” operate of SceneDelegate I’m calling this

    let mainStoryboard: UIStoryboard = UIStoryboard(identify: "Important", bundle: nil)

    guard let vc = mainStoryboard.instantiateViewController(withIdentifier: 
    "FindFalconeVC") as? FindFalconeVC<FindFalconeVCViewModel> else {fatalError("FindFalconeVC")}

    vc.viewModel = FindFalconeVCViewModel(webservice: FindFalconVCServices())
    AppDelegate.shared.nvc = UINavigationController(rootViewController: vc)
    AppDelegate.shared.nvc?.isNavigationBarHidden = true
    UIView.transition(with: (SceneDelegate.shared?.window)!, length: 0.33, choices: UIView.AnimationOptions.transitionCrossDissolve, animations: {
        SceneDelegate.shared?.window?.rootViewController = AppDelegate.shared.nvc
    }, completion: nil)

ViewController isn’t instantiating. If I cross viewmodel from inside, it’ll instantiate however then I need to use protocol in order that it’s higher whereas writing check circumstances through the use of mock viewmodel and observe BASIC ideas as effectively.



Please enter your comment!
Please enter your name here

Most Popular

Recent Comments