CoreData not firing faults

168 Views Asked by At

I am working on a Tabbed Application and have been struggling with a CoreData issue for a while now. I will do my best to be clear enough.

The app starts with a tab, which fetches certain types of objects from CoreData (together with their To-Many relationship) and displays the data in a certain way. In another tab, I have a UITableView, which uses NSFetchedResultsController to display different kind of objects. Both tabs use the same NSManagedObjectContext. There are additional tabs that do not use CoreData or any previously retrieved objects.

When I enter the first tab, everything works and is displayed correctly. When I navigate from there to a tab which doesn't use CoreData and go back again, everything is still fine. However, when I navigate to the tab with the UITableView and NSFetchedResultsController then back again, my objects in the first tab are faulted. This doesn't surprise me much, but I can't seem to be able to fire them. I am trying to access object's To-Many relationship and the count value, which - from what I know - should fire a faulted object.

I am not sure what to think about this behaviour. Can it be that the NSFetchedResultsController somehow messes up previous fetches? That doesn't sound reasonable...

Also, just so you know, I am using Swift, but that should not be affecting anything.

Any input will be appreciated! Thanks!

1

There are 1 best solutions below

0
On

It's hard to answer this kind of question without seeing the actual code. However it appears your fetchResultController's results are being changed during the navigation. A good practice would be, try to execute your fetchRequest and feed it to the fetchResultController in your ViewController's viewWillAppear.