Broken SwiftUI previews

Whenever I use @ObservedResults or @ObservedRealmObject in a view my SwiftUI preview stops working. Is there some obvious setup step that I am missing so this works reliably?

@Thomas_Rademaker you can refer our sample apps. Find them in ‘realm-swift/examples/ios/swift/RealmExamples.xcworkspace’

I just rechecked the latest version of RealmSwift (v10.24.2) - previews for SwiftUI are working fine for me.

1 Like

Thank you @Pavel_Yakimenko . I’ll take a look through the sample apps.

I figured out my issue. I’ll leave the solution here in case anyone else runs into a similar problem.
I set a custom realmConfiguration in the environment with this view modifier,

.environment(\.realmConfiguration, Storage.realmConfiguration)

In my SwiftUI PreviewProvider I must include the same environment view modifier.

So, not a Realm bug but me not understanding how the SwiftUI PreviewProvider works.