Hi all,
I have a book club app I'm developing that utilizes SwiftData and Cloudkit. From what I've learned, the way to display lists that can update in real time across multiple devices is to retrieve an array of the model objects via the Query keyword then use a computed property to sort and filter the array to your liking, and reference that computed property when you need to display the list. This works, but it seems inefficient to grab every single object of a given model and sort / filter it each time.
The other method I've been trying was, for example, after the user selects a Book object that comes from a queried list populated via the method above, to pass that Book object through the program so I can access its properties to display their lists (and it should work right because that initial book property came directly from a queried array of Books?).
For instance, a Book object has an array of Readers. After a user selects a Book, I can pass that Book object to the ReaderView class and display itsreaders array, and it should update in real time on CloudKit since that Book object came from a queried Books array. The benefit of this is you don't have to do as much sorting and filtering. But unfortunately, I've had mixxed results doing it this way, and it seems that the further you get away from the original object, the less success I've had getting it to update in real time. For instance, if I try to access a Reader objects Comments array property, it might not work.
Anyways, I'm wondering if I should generally just keep it simple and stick to the first method I mentioned, or if there is a pattern that people generally follow?