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

Open
opened 2025-12-29 15:28:11 +01:00 by adam · 2 comments
Owner

Originally created by @matrosovDev on GitHub (Aug 13, 2019).

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)
        }
    }
Originally created by @matrosovDev on GitHub (Aug 13, 2019). Can you please comment on this [question](https://stackoverflow.com/questions/57429039/corestore-how-to-observe-changes-in-database) 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) } } ```
adam added the question label 2025-12-29 15:28:11 +01:00
Author
Owner

@matrosovDev commented on GitHub (Aug 15, 2019):

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 commented on GitHub (Aug 15, 2019): 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?
Author
Owner

@JohnEstropia commented on GitHub (Sep 22, 2019):

@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 commented on GitHub (Sep 22, 2019): @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
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#285