35

I upgraded my project to Xcode 8. Now, I'm getting this error log with Xcode 8 and iOS 10 combination.

Setting the cacheName to nil in the below code seems fix it.

NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:NULL cacheName:@"myCache"];

What should I do to get rid of this error log and use cache in my FRC?

iCanCode
  • 1,001
  • 1
  • 13
  • 24
  • If you are trying this on the simulator, then, can you try resetting it by going to Simulator -> Reset Content and Settings. Also, clean the project. – Kunal Shrivastava Sep 22 '16 at 14:02
  • Tried. Doesn't help :( – iCanCode Sep 22 '16 at 15:43
  • 1
    Seeing the error on real devices as well after the upgrade to Xcode 8 / iOS 10. – jk7 Sep 23 '16 at 00:26
  • 1
    Also seeing this on real devices just now after upgrading – daveywc Sep 23 '16 at 00:49
  • 1
    This error pops up for me on calling -save on the context. But I only get output from the system - the NSError returned from the save method is still nil so it looks to only be a warning. I haven't seen any irregular behaviour caused by it, so for now I may just leave it be. – aronspring Sep 26 '16 at 15:06

3 Answers3

27

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 you will open one or more file descriptors pointing to the sectionInfo cache file of the fetchedResultsController. This means that if you save context 255 times, you will reach the maximum number of files that can be opened on devices and no new resources may be opened, causing any subsequent opening of xib files, images, database, etc. to fail.

The problem occurs also for apps already on production (built with xcode 7) on devices upgraded to iOS 10.

A temporary solution is disabling NSFetchedResultsController caching with nil as cacheName:

NSFetchedResultsController *frc = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:NULL cacheName:nil];

Obviously in this way we can't get advantage of caching. I hope Apple will fix the bug asap. I am going to test against 10.2 beta 1.

OPEN RADAR 28361550

EDIT On iOS 10.2 beta 1 the bug does not occur: it has been solved (for now).

Donnit
  • 1,217
  • 12
  • 19
  • 4
    I cannot guarantee it is the same issue, however I am still seeing this error in iOS 10.2 on a real device. Removing the cache from my FRC solves the problem, so I suspect the issue is related. – user3847320 Jan 03 '17 at 16:37
2

First time I'm offering an answer here, but here goes...

I experienced this error and have found a resolution for my particular case.

I was using an NSFetchedResultsController. I then went back to add State Restoration. This error then began to appear upon restoration. When I used the navigation bar to go back to a previous view controller, the data were all missing/incorrect.

On reading the NSFetchedResultsController docs, I discovered the following:

Important

A delegate must implement at least one of the change tracking delegate methods in order for change tracking to be enabled. Providing an empty implementation of controllerDidChangeContent(_:) is sufficient.

I simply implemented an empty controllerDidChangeContent(_:) as directed. Now, everything works fine and the error message from the question is gone. To be clear, I simply added the following code in each view controller with a fetched results controller:

// NSFetchedResultsController change tracking methods
    func controllerDidChangeContent(_ controller: 
NSFetchedResultsController<NSFetchRequestResult>) {
        // empty: see documentation
    }

Hope this helps.

Community
  • 1
  • 1
curieux
  • 713
  • 1
  • 7
  • 15
  • You surely have a controller:didChangeObject:atIndexPath:forChangeType:newIndexPath: which suffices this requirement. – malhal Sep 10 '18 at 16:01
0

After paying more attention to the above error message, I could see that your App was creating a large amount of File Descriptors, opening files in a cache folder and never closing or releasing them. So it better to disable the NSFetchedResultsController caching for now.

Hope Apple will fix the issue

Saranjith
  • 11,242
  • 5
  • 69
  • 122