A handful of Xcode file templates for projects that use RXSwift and MVVM
These file templates are meant to be used for the following app architecture setup:
Let's call each "screen" or "view" in the app a Scene. So if you have an app that has a list view, a detail view and a login view you have 3 Scenes.
Each Scene consists of the following elements:
-
A ViewController (that displays the data from the ViewModel out and sends user input to the ViewModel input using binding in both cases)
-
A ViewModel (that provides the ViewController with displayabe Data by defining one or more transformation chains connecting the input to the output)
-
A Router (that takes care of routing to another scene)
-
A Builder (that initializes and connects the Router, ViewModel and ViewController and returns the ViewController)
In most cases the ViewModel uses other helper objects (e.g. an APIClient) to access and mutate the model or download data but those might be shared by multiple Scenes so I don't consider them part of a scene.
-
Download the RxSwift folder and add it to the following folder on your machine:
~/Library/Developer/Xcode/Templates
-
When you want to add a new scene to your app, open the New File dialog and choose RxSwift in the left column
-
Select Scene and click Next
-
Enter a name for the Scene. As you can see that name will be used as a prefix for all the 4 classes that will be needed for the scene (see above)
-
Click Next and save the scene. Xcode now creates the 4 classes needed for the scene. You will get 2 compile errors, because you still have to create the APIClient that the ViewModel references.