2

I try to observe the changes in @FetchRequest publisher by using onReceive as shown in the code bellow, It's work but I have on issue I want to fix it, the publisher publish to many values and I just want to receive one value to know the change in @FetchRequest is happened.

Example Code

struct TodayView: View {
 
    @FetchRequest(fetchRequest: TodoTaskManager.allOverdueTasksFetchRequest)
    private var overdueTasks: FetchedResults<TodoTask>

    // Some views...

    .onReceive(overdueTasks.publisher.count()) { _ in
        print("tasks count: \(overdueTasks.count)") // The print times equals tasks count x 2
       }
}
Ammar Ahmad
  • 534
  • 5
  • 24
  • I tried to use the publisher for a FetchRequest in a similar way but gave up because to much data was being published – Joakim Danielson Nov 26 '22 at 11:17
  • [Mirror thread](https://developer.apple.com/forums/thread/690302?login=true&page=1) over on the Apple Developer Forums – Rob S. Jan 24 '23 at 20:29

0 Answers0