CoreStore icon indicating copy to clipboard operation
CoreStore copied to clipboard

List monitor contains updated data but calling fetchAll in main thread does not return updated data

Open matrosovDev opened this issue 5 years ago • 2 comments

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)
        }
    }

matrosovDev avatar Aug 13 '19 12:08 matrosovDev

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 avatar Aug 15 '19 08:08 matrosovDev

@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

JohnEstropia avatar Sep 21 '19 23:09 JohnEstropia