Local Realm, SwiftUI and MVVM

I am just digging in to Realm with SwiftUI using Realm 10.22.0 and RealmDatabase 11.9.0

I would like to use the MVVM design pattern, but am unclear of how to do this in SwiftUI using the ObservedResults and ObservedRealmObject.

In the only example I have seen, these property wrappers are used within the View and not in a ViewModel or is this more of a set of convenience property wrappers like CoreData’s FetchRequest or FireBase’s new FirestoreQuery property wrapper.

If that is the case, and I want to use the MVVM design pattern, what is the recommended strategy? Is it to use NotificationToken and set up an observer?

I had a similar struggle. I ended up having to set up my own publisher, but it’s been working so far. You can see the details here: Best practices for having @RealmObservedObject inside a ViewModel (ObservableObject)

1 Like