Simple example of an MVVM+C implementation.
- Create a non trivial app using MVC as given by apple. Build up "massive view controllers" or at least tightly coupled. They should have the following inside each UIViewController:
- Model/Business
- Navigation/Routing
- Networking
- Refactor logic item by time towards a goal of MVVM+C. Each iteration should have:
- An issue associated with it
- Issues can serve as a kind of dev diary
- Polish well factored POC into a fully functioning MVP of Planning Poker
- Explore evolving this architecture towards a declarative and reactive paradigm using Combine and SwiftUI
- Make the case for MVVM as a prefered transitional design pattern that is useful for a UIKit world and later for a SwiftUI world
The Model-View-ViewModel (MVVM) pattern helps to cleanly separate the business and presentation logic of an application from its user interface (UI)
Strengths of using this pattern primarily are:
- Separation of concerns
- Easy to reason about
- Testability
- Model: Struct/Class
- View: UIView(Controller)
- ViewModel: Class
Model <-> ViewModel <-> View
The Model and View never actually talk to each other.
We can use a State
type to represent a view's ... well state. This creates a unidirectional data flow for UI updates:
Model -> ViewModel -> State -> View
.
There is also a parallel flow that handles updates or actions from the user in the view:
View -> ViewModel -> Service -> Model
An illustration of these data flows: