Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI - How can I know when my FetchedResults changes?

Tags:

ios

swift

swiftui

I'd like to pass to my model the newest fetched data of my core data entities, in order to have them synched.

Is this possible?

The reason is that I have many variables that have to be calculated from the data saved in core data. These values are used in my views, so they should update at the same time.

(Until now I just found a way to pass them around every time with functions, but I find this very chaotic...)


Until now:

func doSomethingWithFetchedData(fetchedData: FetchedResults<Entity>) {
    //return what I need
}

Thanks!

like image 762
Mofawaw Avatar asked Dec 02 '25 10:12

Mofawaw


1 Answers

NSFetchedResultsController Subscribing to updates for many objects matching a fetch request has been easier than subscribing to updates from a single managed object, thanks to NSFetchedResultsController. It comes with a delegate that informs us about changes to the underlying data in a structured way, because it was designed to integrate with tables and collection views

Here is a good link to start with

like image 181
Jawad Ali Avatar answered Dec 04 '25 00:12

Jawad Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!