Member-only story
Rethinking MVVM in SwiftUI: My Proposed Approach in using MVVM
SwiftUI itself is already MVVM?
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.
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…