NSFetchedResultsController: changing predicate not working?

I had almost exactly this problem, until I found the hint in a very recent blog post at iphone incubator NSFetchedResultsController is caching the first results. (You probably have something set at initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName) I’m guessing your code (like mine) is a derivation of the CoreData sample, so assuming it’s @”Root”, before you change the predicate, … Read more

Core Data – How to fetch an entity with max value property

You set the fetchLimit to 1 and sort by personId in descending order. E.g.: NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] initWithEntityName:@”Person”]; fetchRequest.fetchLimit = 1; fetchRequest.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@”personId” ascending:NO]]; NSError *error = nil; id person = [managedObjectContext executeFetchRequest:fetchRequest error:&error].firstObject;

iOS 9 – “attempt to delete and reload the same index path”

This seems to be a bug in iOS 9 (which is still beta) and is also discussed in the Apple Developer Forum iOS 9 CoreData NSFetchedResultsController update causes blank rows in UICollectionView/UITableView I can confirm the problem with the iOS 9 Simulator from Xcode 7 beta 3. I observed that for an updated managed object, … Read more

Illegal attempt to establish a relationship ‘xyz’ between objects in different contexts

You can’t have relationships between objects in different managed object contexts. So one way of getting around that is to bring the object into the managed object context. For example: NSManagedObject *book = // get a book in one MOC NSManagedObject *owner = // get an owner in a different MOC [[owner mutableSetValueForKey:@”books”] addObject:[owner.managedObjectContext objectWithID:[book … Read more

NSFetchedResultsController crashing on performFetch: when using a cache

I had a similar problem with one of my apps, when the Apple released the new iOS 4.0. Search: fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:[self managedObjectContext] sectionNameKeyPath:nil cacheName:nil]; And set the value of the parameter cacheName to nil. It worked for me, hope it will for you. Let me know.

Is there a way to instantiate a NSManagedObject without inserting it?

For what it’s worth, Marcus Zarra seems to be promoting the nil context approach, claiming that it’s expensive to create a new context. For more details, see this answer to a similar question. Update I’m currently using the nil context approach and have encountered something that might be of interest to others. To create a … Read more

NSPredicate: filtering objects by day of NSDate property

Given a NSDate * startDate and endDate and a NSManagedObjectContext * moc: NSPredicate *predicate = [NSPredicate predicateWithFormat:@”(date >= %@) AND (date <= %@)”, startDate, endDate]; NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; [request setEntity:[NSEntityDescription entityForName:@”EntityName” inManagedObjectContext:moc]]; [request setPredicate:predicate]; NSError *error = nil; NSArray *results = [moc executeFetchRequest:request error:&error];