If I perform a fetch w/ a NSFetchedResultsController that returns objects and then want to clear the controller, i.e., have .fetchedObjects be an empty array, is there a method that can be called or do I have to perform another fetch that does not return any results?
2 Answers
You could set the fetch request of your fetched results controller to return nothing:
self.fetchedResultsController.fetchRequest.predicate =
[NSPredicate predicateWithValue:NO];
[self.fetchedResultsController performFetch:nil]
Now self.fetchedResultsController.fetchedObjects
should return an empty array.
The question doesn't make a lot of sense. An NSFetchedResultsController
's data is the result of a fetch request. For fetchedObjects
to be empty, the fetch request would have to return an empty set. That would imply that there were no objects satisfying the fetch request. If there are objects that satisfy the request, then fetchedObjects
will not be empty. What you're asking amounts to asking how to ensure that a fetch has no results.
I'm not even sure why you'd want this. If you're not going to be using the results of the fetch any more, just get rid of the NSFetchedResultsController
. Why keep it around if you don't want its results any more?