views:

31

answers:

1

I was given a framework written by other programmers to access the core data. In this situation i receive a pre-loaded NSFetchedResultController which I need to filter, to display a part of it's data.

Here is what I tried:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category==%@", @"current"];
[NSFetchedResultsController deleteCacheWithName:@"Root"];
[myResultController.fetchRequest setPredicate:predicate];
myResultController.fetchedObjects = [myResultController.fetchedObjects filteredArrayUsingPredicate:predicate];

And i get an error saying that object cannot be set, either setter method is missing, or object is read-only.

So whats the best way to filter an NSFetchResultController which is already loaded, without having to store the filtered data into another array?

+4  A: 

fetchedObjects is readonly. You cannot set it manualy.

What you need to do is to perform a new fetch with your myResultController.

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"category==%@", @"current"];
[NSFetchedResultsController deleteCacheWithName:@"Root"];
[myResultController.fetchRequest setPredicate:predicate];
//myResultController.fetchedObjects = [myResultController.fetchedObjects filteredArrayUsingPredicate:predicate];
[myResultController performFetch:nil];
vfn
thanks i'll give it a try
aryaxt