I am using Clean Architecture in Swift. I am doubtful about routing in it.
Consider this scenario: A screen needs to be pushed when a button is pressed in ViewController
Now there may be two cases:
Ankit, I would like to point out that all data transactions across the routing units should be initiated upon business logic derived propagations, optionally stateful.
An interactor is there in order to translate the in/out data from the entity layer to the presenters, making the presenter independent from the system state encapsulated in the entity layer and thus more testable. It makes it suitable for propagating entity specific bits of data into router, which would go on to forward it to a new stack of a view-presenter-interactor.
A presenter is there in order to provide a stateful interface for the view. In cases where specific data transformations are not needed and the interactor is omitted, it's considered normal to propagate events from the presenter through the router and to another stack of view-presenter-interactor.
However, what is not normal is to have a direct event propagation from the view (UIViewController in your case) to the router for the reason that it creates a direct binding of a navigation scenario and there is simply no way to insert the business logic opportunistically because the presenter is not participating in the transaction.
So, I would like to state that yes, it will break Clean. Propagate to router either from the presenter or the interactor. This extends even to the cases where the event can be represented as a Void Swift empty tuple value hence propagating literally no data whatsoever.
You should not call the router directly from ViewController.
The responsibility to make the decision to navigate to some place is taken from the interactor. It's pure business logic.
ViewController should not know when to navigate. ViewController tells the interactor: "the button has been pressed", then the interactor tells the presenter "This scene must be presented", and finally the presenter must tell ViewController that he must show that scene, which calls the router to perform the navigation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With