CoreStore
CoreStore copied to clipboard
List monitor contains updated data but calling fetchAll in main thread does not return updated data
Can you please comment on this question
I have prepared workaround by getting values from list monitor but not sure if it's correct. I would like to call fetchAll after listMonitorDidChange actually when core data records are updated.
func listMonitorDidChange(_ monitor: ListMonitor<ExerciseEntity>) {
var exerciseFromMonitor = [ExerciseEntity]()
for index in (0...monitor.numberOfObjects() - 1) {
exerciseFromMonitor.append(monitor[index])
}
print(exerciseFromMonitor)
if exerciseFromMonitor.count > 0 {
//updateData(with: routinesFromMonitor)
}
}
Looks I figure out, how it works, so evertyime data is changed in CoreData list motor is notified about it and already exist with needed data in it, as I understood we just need this callback function to reload data for example and etc.
My question is can I search through monitor. So I need to search or filter this:
let monitor = CoreStore.monitorSectionedList(
From<ListEntityType>()
.sectionBy(#keyPath(ListEntityType.muscle.name)) { (sectionName) -> String? in
"\(String(describing: sectionName)) years old"
}
.orderBy(.ascending(\.name))
)
do I need to reassign let monitor
property each time when I search?
let's say textfield triggered by entering a latter should I init monitor
again with some .where statement?
@matrosovDev ListMonitor would not be your tool for the job here. I would suggest to use a plain fetchAll
whenever your textField triggers a new search