up a portion of your app’s user interface.” — Apple, UIViewController Class Reference “View controllers are traditional controller objects in the Model-View- Controller (MVC) design pattern” — Apple, About View Controllers
of a Presentation Model is of a fully self-contained class that represents all the data and behavior of the UI window, but without any of the controls used to render that UI on the screen. A view then simply projects the state of the presentation model onto the glass.”
Separation of Concerns is easy to enforce • VMs can’t know about VCs! • VCs are much shorter and the routing is clearer • VM code is reusable and decomposable • Testable, finally
themselves can get pretty hairy • VM interface design often ends up being iterative • Bindings • Don’t work with collections or primitives • KVO requirement can be painful • Debugging is declarative and hunting down bugs isn’t always easy
mix up View and ViewModel code • Option 1: Selectively forward delegate and data source methods to ViewModel • Option 2: Have the VM be the data source and forward delegate methods as needed
properties if needed • Don’t use UITableViewController (like, ever) • Don’t set ViewModel as UITableView dataSource • Forwards most methods delegate and dataSource methods • UITableViewCells are View + ViewModel • ViewModel owns fetchedResultsController
VCs from business logic, formatters, validation, storage, and complex view hierarchies • Use a ViewModel or Presenter to represent the state of your UI abstracted from view code • Bindings simplify links between layers, but aren’t the only way that works • Experiment to figure out what works best for your team