Notify when @FetchRequest changes?

Hello

    @FetchRequest(
        entity: Book(),
        sortDescriptors: []
    ) var books: FetchedResults<Book>

How can I get notified when books changes?

I was thinking about putting this...

 .onReceive(NotificationCenter.default.publisher(for: .NSManagedObjectContextDidSave), perform: { _ in})

... in my main View but this would notify me if anything gets saved and that is not what I want. I want to get notified just if a certain FetchRequest changes (in this case books)?

How can I do that?

Thank You!

.onRecevier(books.publisher){ Changs in
      ....
}

Is there another way? Because this .onRecevie(books.publisher) repeats too many times, I want it to execute one time?

Mirror question on Stack Overflow.

I'm sure I'm going to hose the Combine terminology... but onReceive takes anything that conforms to Publisher. Trigger an auto-complete after the publisher to see what I mean.

In your case, collect() seems like what you want?

Collects all received elements, and emits a single array of the collection when the upstream publisher finishes.

I'm looking to be notified when any change occurs, but not of the individual items. collect() is perfect for me. Someone with actual Combine knowledge can likely offer something better :)

Notify when @FetchRequest changes?
 
 
Q