Building an iOS app using SwiftUI + Combine + MVVM [Part 2]

Learn step by step how to build an iOS application using the brand new Apple frameworks.

Finsi Ennes
Level Up Coding
Published in
6 min readJun 4, 2020

--

This article guides you through building a complete app using only and exclusively those frameworks. Not only that, but we will also use a design pattern that has been gaining more and more traction in the Apple devs community. This is the MVVM architecture.

Before starting, note that this is the second part of the tutorial. For a better understanding of the exercise, please check out the previous part. It includes the app presentation and all details related to the code structure using MVVM. In this first part, we also implemented the model:

In this article, we will start working with SwiftUI and Combine, so we assume that you have some knowledge in these in these frameworks. If that isn’t the case, I’d recommend you start for the basics:

What we will build

At this point, we have a well defined model. It includes several entities and use cases that represent the business logic of our application. Thus we already have everything to start building the presentation layer.

As we commented in the first part tutorial, we implemented a MVVM architecture inspired by Airbnb’s MvRx approach. This uses a view-specific state instead of a global app state. Taking this into account, we’ll see how to adapt that solution using SwiftUI+Combine.

We will start building a generic implementation for the ViewModel component. Once we have clear how this works and its functions, we will be ready to build the application views with their specific view models. In this part we are going to implement the book list view.

ViewModel generic implementation

As you know, a design pattern can be implemented making use of several approaches. For this exercise we are looking for a generic implementation of a ViewModel that follows the MvRx approach. In this way, solution…

--

--

iOS Developer. Passionate about coding and UX design. For more content, you can follow me on Instagram @finsi.code