5
votes

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
Set NSFetchedResultsController to nil.Sandeep
This would not work with the lazy instantiation typical for FRC.Mundi

2 Answers

12
votes

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.

0
votes

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?