Benefits We don’t need to to test the UI (actually we should) We can implement app logic without any UI view model is easy testable view model are (almost) platform independent
Instantiation Every controller has viewModel property Some views may have separate view models Inject view model to controller during instantiation Inject view model’s important properties during instantiation
ViewModel for tableviews ViewModel has “rows” property of type NSArray Row is some NSObject subclass with data very coupled to cell Formatters, etc. are applied to row class, not cell Controller binds to “rows” and reloads data after property changes
Testing State of model can be determined in any moment Property change affects view model internal state RACCommand changes view model state RACSignal pushes new state to subscribers ViewModel tests are very obvious and atomic:
Functional Reactive view model The login button can be pressed when username and password aren’t blank ! The error should be cleared after 5 seconds it was displayed