Testing Your First View Model


In this episode, we test the view models of the settings view controller. We start with the SettingsViewTimeViewModel struct. Create a new file in the Test Cases group we created in the previous episode and choose the Unit Test Case Class template.

A Few More Unit Tests


Writing units tests for the view models of the WeekViewController class is just as easy as writing unit tests for the DayViewViewModel struct. We start with the unit tests for the WeekViewViewModel struct.

Taking MVVM to the Next Level


You should now have a good understanding of what MVVM is and how it can be used to cure some of the problems MVC suffers from. But we can do better. Up until now, data in the application has flown in one direction. The view controller asks the view model for data and populates the view it manages. This is fine and many projects can greatly benefit from this implementation of the Model-View-ViewModel pattern.

What Are the Options


The question we need to answer in the next few episodes is "How can we tie everything together?" This is a problem many developers new to the Model-View-ViewModel pattern struggle with. It's not difficult to use the Model-View-ViewModel pattern to push data from the controller layer to the view layer. We've already covered that extensively in this series. But how do you respond to user interactions or changes of the environment, and update the user interface? Automatically.

DIY Bindings


Before we use RxSwift to implement the Model-View-ViewModel pattern, I want to show you how you can use closures to implement a custom solution. I usually refer to this solution as "DIY bindings" or "Do It Yourself bindings".

Why RxSwift


Before we refactor the AddLocationViewViewModel class, I'd like to take a few minutes to explain my motivation for using RxSwift and RxCocoa. There are several reasons.

About Bart Jacobs

About bart jacobs

My name is Bart Jacobs and I run a mobile development company, Code Foundry. I've been programming for more than fifteen years, focusing on Cocoa development soon after the introduction of the iPhone in 2007.

Stop Writing Swift That Sucks

In my free book, you learn the four patterns I use in every Swift project I work on. You learn how easy it is to integrate these patterns in any Swift project.