I haven’t worked with tables outside of Apple’s macOS tutorial, but it looks very similar to working with Lists, so I think the @ObservedResults or @ObservedRealmObject property wrappers would work great for this case.
Apple’s SwiftUI on the Mac: Build the Fundamentals tutorial has you building a garden tracking app. Here’s the sample project code: Building a Great Mac App with SwiftUI. In that code, Apple’s app uses an @EnvironmentObject var store: Store
, from which you get plants
to populate the table.
Depending on the structure of your app, you could use either @ObservedResults or @ObservedRealmObject in place of this environment object to store your garden details and populate your table. ObservedResults is an observed list of query results that invalidates/updates the view when objects in the results set are updated. ObservedRealmObject observes a specific object and automatically invalidates/updates the view when the object changes. Our SwiftUI Guide has some more details that might help you decide how best to structure this. Or check out our Realm + SwiftUI Quickstart to see these property wrappers in action.
For more complex cases, I haven’t watched it yet, but Stewart Lynch recently released a YouTube video tutorial about using Realm + SwiftUI with Notification Tokens instead of the @ObservedResults property wrapper. If you’ve got a more complex case where our @Observed property wrappers don’t work for you, this tutorial might help.