0

So, I've an iOS project that needed to be revamped and added with a routing / navigation logic between views. We have 3 ways as the entry point of the routing: manually, push notification, and deeplink. I am using MVP and I was thinking that maybe I will just have 3 different presenters for each entry point. Eg. we will have HomePresenting protocol for the HomeViewController and it will have HomePresenter: HomePresenting, PushNotificationHomePresenter: HomePresenting, DeeplinkHomePresenter: HomePresenting. And the Coordinator / Router / Navigator class will just set this presenter based on the type of entry point like so:

function navigate(to screen: ScreenType, routeType: RouteType) {
    ....
    
    if screen == .home {
        let vc = HomeViewController(nibName: "HomeViewController", bundle: Bundle.main)
        if routeType == .manual {
            let presenter = HomePresenter(delegate: vc)
            vc.presenter = presenter
        } else if routeType == .deeplink {
            let presenter = DeeplinkHomePresenter(delegate: vc)
            vc.presenter = presenter
        } else if routeType == .pushNotif {
            let presenter = PushNotificationHomePresenter(delegate: vc)
            vc.presenter = presenter
        }
        navigationController?.pushViewController(vc, animated: true)
    }

    ....
}

The reason for this is that the logic between those entry point might be different. For instance: a product subscription deeplink will just directly open the SubscriptionViewController if there is no product saved in the local Realm database in the device. But if it found a product, it will just open HomeViewController and show a message "You have subscribed to product xxx." While if we go to the HomeViewController manually, there won't be any logic to check this up.

Is this a good idea? Also, the same question with MVVM as in can I just set the View Model from the Coordinator etc?

Thank you.

1 Answer 1

-1

Not only is this a good idea, it's recommended.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.