Member-only story
Implementing Clean MVVM With SwiftUI
How to properly use the MVVM pattern in SwiftUI
There are tons and tons of tutorials out there about the topic. However, I couldn’t find anything explaining clearly how to handle complex situations that can happen in a real-world application.
All the examples I could find were basic: they start with a simple view where they put some data fetched by the view model. The View Model is kept alive by the view using @StateObject
or @ObservedObject
variables. And that’s it.
In real-world applications, we have dependencies and pieces of logic that need to be properly orchestrated. We have subviews to which we need to pass bindings. None of these problems is properly described in the articles I found.
In today’s article, I’d like to go deeper into this architectural issue and help everybody go one step further with MVVM and SwiftUI.
The App
We are going to build the notification settings of an app. The app lets the user control whether they want the notification locally. Then, the app shows when it will show a reminder to the user. The picker to choose the date is shown only if we have the permissions to schedule the notifications from both the system and the app itself.
Upon tapping on the Reminder at
, the user can update the time in which the notification is scheduled.
To give the feeling that the app is real, we will embed the settings screen into a TabView
with a Hello World Home Screen.
This is the expected result:

To build this app, we need to implement a few components. I’ll share all the code, going through the article, plus the final project in the conclusions.
I’ll try to focus only on the parts that are really important for the architecture, skipping all the details such as Dependency Injection, how to request the push notification permissions and similar.
The Model
When developing an app, we should start by thinking about the data model. What do we…