MVVM-C
lastmod 2025-11-06created 2025-11-043 edits
MVVM-C stands for Model-View-ViewModel-Coordinator, a structure that adds the Coordinator pattern to the MVVM architecture.
MVVM reduces the dependency between View and ViewModel and improves testability, but it has the problem that screen transition (navigation) logic gets mixed into the ViewController or ViewModel.
To address this, the Coordinator takes over sole responsibility for screen transitions.
Components
Model
- Handles the app's core data structures and business logic.
- Stores and processes data from API call results or fetched from the DB.
View
- The screen (UI) shown to the user.
- Subscribes or binds to the ViewModel to reflect state changes.
- Contains no business logic; it only handles display.
ViewModel
- The intermediate layer between View and Model.
- Handles input events from the View, fetches data from the Model, processes it, and passes it to the View.
- Connected to the View through binding or a reactive framework such as RxSwift or Combine.
- Contains no screen transition logic.
Coordinator
- An object responsible for navigation between screens and flow control.
- Responsible for creating ViewControllers and for screen transitions (push, modal, present, etc.).
- Separates navigation logic from the ViewController and ViewModel, keeping the structure cleaner.
MVVM-C flow
- When the app starts, an AppCoordinator is created and sets up the root screen.
- The Coordinator creates and connects the ViewController and ViewModel.
- The View is bound to the ViewModel and handles data and events.
- When a screen transition is needed, the ViewModel passes a request to the Coordinator (usually via a Delegate or Closures).
- The Coordinator creates a new ViewController and performs the navigation.
Pros of MVVM-C
- Separation of concerns: screen transition logic is moved into the Coordinator, simplifying the ViewController and ViewModel.
- Testability: since the ViewModel has no screen transition logic, it is easy to unit test independently.
- Better maintainability: the navigation structure can be managed in one place, making flow changes easier.
- Reusability: flows can be reused or managed independently per Coordinator.
Cons of MVVM-C
- More complex structure: adding a Coordinator may be overkill for small projects.
- More boilerplate code: there may be a lot of code for creating and connecting Coordinators.
- Learning curve: team members need time to understand and apply the MVVM-C pattern.
See also
Favorite site
Pages that link here