NSFetchedResultsController with fetch predicate
NSFetchedResultsController with fetch predicate
- Subject: NSFetchedResultsController with fetch predicate
- From: Rick Mann <email@hidden>
- Date: Fri, 20 Nov 2009 21:37:02 -1000
I have a UITableView that displays a list of message subjects. When a message is deleted, it is marked as deleted, rather than actually removed from the MOC.
The list is backed by an NSFetchedResultsController. I initializes the FRC with a predicate:
NSEntityDescription* entity = [NSEntityDescription entityForName: @"NewsItem"
inManagedObjectContext: appDelegate.managedObjectContext];
NSFetchRequest* req = [[NSFetchRequest alloc] init];
req.entity = entity;
NSPredicate* pred = [NSPredicate predicateWithFormat: @"deleted == false"];
req.predicate = pred;
NSSortDescriptor* sd = [[NSSortDescriptor alloc] initWithKey: @"date" ascending: false];
NSArray* sds = [[NSArray alloc] initWithObjects: sd, nil];
[sd release];
req.sortDescriptors = sds;
[sds release];
mFetchedResultsController = [[NSFetchedResultsController alloc]
initWithFetchRequest: req
managedObjectContext: appDelegate.managedObjectContext
sectionNameKeyPath: nil
cacheName: @"AlertsCache"];
[req release];
mFetchedResultsController.delegate = self;
But when UI actions cause an instance to have its deleted property set, while I get a changeUpdate notification, it doesn't seem to actually remove it from the fetchedResults. If I try to delete the table row for that item, it throws an exception, since there are too many items in the fetchedObjects array.
I tried issuing the performFetch again, but it has no effect.
When does the FRC actually send insert/delete notifications? Does it take any fetch predicates into account when it does this? If not, it's not very useful.
TIA,
Rick
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden