NSAsynchronousFetchRequest
seems like an answer to read large amount of data from CoreData, without blocking main thread.
But, it is lacking some key features, provided by NSFetchedResultsController.
The key features are :-
-
In
NSFetchedResultsControllerDelegate
didChange and controllerDidChangeContent, we automatically receive a complete change information of persistence store. This enables us to implement the animation of add/delete/move/modify in collection view. -
Always listen to DB changes. Whenever there is changes being written into the persistence store,
NSFetchedResultsControllerDelegate
didChange
andcontrollerDidChangeContent
will be triggered automatically. This enables us to ensure our UI is in sync with DB.
But, NSAsynchronousFetchRequest
doesn't come with NSAsynchronousFetchedResultsController :(
I was wondering, if you were using NSAsynchronousFetchRequest,
how do you implement
- Animation changes on collection view?
- Always listen to DB change?
My initial thought for animation changes on collection view, it seems we can utilise UICollectionViewDiffableDataSource
.
But, I notice it might be highly memory inefficient to do so. We need to keep ALL NSManagedObject in memory, fire all faults during comparison. It looks like we will run out of memory, if there are many rows.
May I know, how do you achieve the following features, if you ever apply NSAsynchronousFetchRequest
in production app?
- Animation changes on collection view?
- Always listen to DB change?
Thanks.