How to clear NSFetchedResultsController?

If I fetch with an NSFetchedResultsController that returns objects and then wants to clear the controller, i.e. to have .fetchedObjects - an empty array, is there a method that can be called or do I need to perform another selection that does not return any results?

+4
source share
2 answers

You can set a query to fetch the result controller to return nothing:

self.fetchedResultsController.fetchRequest.predicate = [NSPredicate predicateWithValue:NO]; [self.fetchedResultsController performFetch:nil] 

Now self.fetchedResultsController.fetchedObjects should return an empty array.

+9
source

The question does not make much sense. NSFetchedResultsController data is the result of a fetch request. For fetchedObjects be empty, the fetch request would have to return an empty set. This means that there were no objects matching the query. If there are objects fetchedObjects request, fetchedObjects will not be empty. You ask how to ensure that the sample does not produce results.

I'm not even sure why you need it. If you are not going to use the results of extraction anymore, just get rid of NSFetchedResultsController . Why store it if you no longer want its results?

0
source

All Articles