Hi,
I just started playing with the new property wrappers and I have a question regarding ObservedResults. Let’s say I have a collection of items and I want to display only a subset of it:
@ObservedResults(Item.self, filter: NSPredicate(format: "lastName begins with A")) var itemList
Later I would like to further filter that subset using a search field:
.onChange(of: searchText, perform: { searchString in itemList.filter = NSPredicate(format: "firstName begins with %@", searchString) })
Everything is working as expected but, when I clear the search field, I get back all the items without any filter (all the Item records from realm). And if, for any reason, SwiftUI re-renders the view, then I get the items properly filtered.
The comment within the ObservedResults implementation says:
A base value to reset the state of the query if a user reassigns the filter
or sortDescriptor
value = try! Realm(configuration: configuration ?? Realm.Configuration.defaultConfiguration).objects(ResultType.self)
That means whenever the filter or the sort descriptor is changed, all the items are received, right?
Is there any way to have returned only the items as they were queried in the beginning?
I hope I made myself clear.
Thank you!
Horatiu