In the traditional MVC model, the View displays the output and lets the Controller know about any actions, such as touch. The Model contains the data while the Controller interacts with both the View and the Controller to render the final output. The View and Controller code can cross paths since you might have to put subviews in the UIViewController (the Controller) which is why the MVVM architecture is used instead.
In the MVVM architecture, which stands for Model, View, and ViewModel. The Model is the same as in MVC and holds the data. The View is shown through the UIView or the ViewController, which prepares for visual output and listens to the Model for changes. The ViewModel is a layer between the Model and the View which deals with the business logic. We don’t touch the View directly and write things to change the View inside the ViewModel. This makes it easier to write Unit Tests as well since we don’t have to test the ViewModel. This architecture avoids over-stuffing the View Controller and compliments the MVC model.

We’ll have the data in the Model class. For our View class, it will contain the labels, imageViews, frames, subviews and all the UI components needed for display. The ViewModel will have the business logic, such as string Names for the View. The Model will contain the data for the View.
The reason why we should use MVVM over any other architecture is that it has a better class separation and makes reusing code simple. This type of architecture will make adding new features and views easier and faster. Also, as mentioned before, it is easier to test.
One Reply to “Project Architecture: MVVM vs MVC”