In the previous chapter, we detailed how the Model-View-Controller (MVC) pattern can be factored in an intuitive and scalable manner. While pervasive in all Cocoa environments, MVC is not the only valid architectural pattern that can be used in Swift. At Microsoft, while working on even driven programming for user interfaces, Ken Cooper and Ted Peters invented the Model-View-ViewModel (MVVM) pattern. In the MVVM pattern, views bind on ViewModels
. Through this binding, ViewModel
provides objects and methods from the Model
layer to the View
layer.
In this chapter, we'll cover the following topics:
- The basics of MVVM
- How to refactor existing MVC code, in order to leverage MVVM
- How to properly use MVVM in complex view controllers
- The advantages and limitations of MVVM