Member-only story
Decoupling Concrete Coordinators From Your Navigation System in iOS
How to split navigation from coordinator instantiation using generic factory
MVVM is one of the most common architectures to realise apps. The goal of this architecture is to lighten the ViewController
responsibilities by moving the presentation logic to another component, the ViewModel
.
MVVM does not explain directly how to tackle the navigation from one ViewController
to another. This issue is so important that a variant of MVVM has been developed: MVVM-C.
The MVVM-C architecture solves this problem by introducing a new set of components, the Coordinators
. Their only responsibility is to properly handle the navigation.
Practically, whenever a ViewController
completes its tasks, it invokes a method of the ViewModel
that asks the Coordinator
to go to the next screen.
This architecture works and all the responsibilities are clearly defined. The components are neatly divided and secluded: ViewControllers
do not know the existence of other ViewControllers
and ViewModels
do not know the existence of other ViewModels
.
The Coordinators
are the components that know about the different Coordinators
in the app. They work like glue, putting everything together.