NewbieBie
NewbieBie

Reputation: 1

Is it allowed to make Multiple navigation in one router VIPER function?

Is it allowed to make Multiple navigation in one router VIPER function? I created just one VIPER router function to multiple navigation.

My code is like this :

func navigateToView(data: [String: Any]) {
        guard let view = viewController else { return }
        if data["callback"] != nil && data["data"] != nil {
            //navigation1(enum: data["enum"] as! Enum, from: view, data: data, callback: { param })
        } else if data["callback"] != nil && data["data"] == nil {
            //navigation2(enum: data["enum"] as! Enum, from: view, callback: { param })
        } else if data["data"] != nil && data["callback"] == nil {
            //navigation3(enum: data["enum"] as! Enum, from: view, data: data)
        } else {
            //navigation4(enum: data["enum"] as! Enum, from: view)
        }
    }

because I saw an article which written The navigation logic, which mean it can use navigation logic in router function

Upvotes: -2

Views: 162

Answers (1)

Husamettin Or
Husamettin Or

Reputation: 1

To answer the question, let's have a look at the parts of VIPER first.

View: Responsible from user interface. Notifies presenter about user actions, lifecycle methods and provides methods to update user interface.

Interactor: Contains business logic. Makes all third party interactions and informs its output (presenter in this case) with use cases.

Router: Responsible from navigation. Provides methods to navigate to other screens.

Presenter: Contains presentation logic such as which data to get , which view to display or which screen to navigate with any user action, lifecycle method or use case.

What navigateToView is doing here to decide which screen to navigate. This should belong to presentation logic since navigation to any screen can be done with user action or according to a field in the data but the router should not know about this.

Let's say you have another button that navigates to the screen in "navigation 1". Then, when the presenter gets the button clicked event, it tells the router where to navigate. It wouldn't tell router the action and router wouldn't decide where to go. The same applies here.

So, it wouldn't be the best practice to use this logic in the router.

Upvotes: 0

Related Questions