Rethinking MVVM in SwiftUI: My Proposed Approach in using MVVM

SwiftUI itself is already MVVM?

Kevin Jonathan
5 min readJun 9, 2024
SwiftUI itself is already MVVM? SwiftUI Image © Apple

Non-Medium Members can read the full story here.

I have been using SwiftUI since 2021, yet I hadn’t realize that I have been doing something fundamentally wrong. Specifically, using SwiftUI alongside MVVM. When creating a simple project, I always thought “Oh I need a design pattern, let’s just use MVVM.”.

Is It Wrong to Use MVVM in a SwiftUI Project?

Since you are the developer, that means you are the one who has the right to decide if it’s wrong or not based on your needs. But after reading several articles like this, I realized that what I usually did was fundamentally wrong. It is because SwiftUI.View already contains ViewModel equivalent functions. This means that if you use SwiftUI with MVVM, it’s like using MVVM on top of MVVM, which is redundant.

Image source: https://medium.com/@karamage/stop-using-mvvm-with-swiftui-2c46eb2cc8dc

In practice, there is a very noticeable weakness when using the MVVM model:

import SwiftUI
import Combine

class HomeViewModel: ObservableObject {
// some variables here and there

func getDataList() {
if…

--

--

Kevin Jonathan

Just a student intricately weaving personal life experience and technology related stuffs, currently navigating the intersections of life.