Title: iphone Core Data - Filtering NSFetchedResultController?
Tags: iphone;core-data;nsfetchedresultscontroller;nspredicate
Question: 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?


Here is the accepted answer: ```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];
```



{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 2.5', 'CreationDate': '2010:00:10/21/10', 'FavoriteCount': 1.0, 'PostTypeId': 1, 'Tags': '<iphone><core-data><nsfetchedresultscontroller><nspredicate>', 'Title': 'iphone Core Data - Filtering NSFetchedResultController?', 'ViewCount': 807, 'id': 3992729, 'user_AboutMe': '', 'user_AccountId': 87569.0, 'user_DisplayName': 'aryaxt', 'user_Reputation': 74133.0, 'user_Views': 3334.0, 'user_id': 242769.0}}