NSFetchedResultsController with relationship not updating

The NSFetchedResultsController is only designed to watch one entity at a time. Your setup, while it makes sense, it a bit beyond what the NSFetchedResultsController is currently capable of watching on its own. My recommendation would be to set up your own watcher. You can base it off the ZSContextWatcher I have set up on … Read more

(NSFetchedResultsController): couldn’t read cache file to update store info timestamps

This error should not be ignored because it can cause app crash. It is related to an iOS 10 bug of file descriptor leaks. There are reports on openradar and Apple Bug Reporter. What happen: if you load a view controller using NSFetchedResultsController with a non-nil cacheName, every time you save the managed object context … Read more

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