NSFetchedResultsController does not update its cache after saving the context

Originator:nskboy
Number:rdar://45072441 Date Originated:October 7 2018, 12:51 PM
Status:New Resolved:
Product:iOS + SDK | Core Data Product Version:iOS 12
Classification:Other Bug Reproducible:Always
 
Area:
Core Data

Summary:
NSFetchedResultsController doesn't detect cache invalidation after inserting new object and saving related NSManagedObjectContext.

Steps to Reproduce:
1. Run the attached sample project. In a nutshell project allows you to manage Parent with Children: insert new Parent, list children of a given Parent, insert new Child to the Parent, move one Child to another Parent. Last operation (move) triggers a bug.
2. Tap Add at the Parents screen to insert new Parent.
3. Navigate to newly inserted Parent and add one Child.
4. Return back to Parents screen and add yet another Parent.
5. Navigate to the inserted parent screen to make sure its content is empty and force creation of NSFetchedResultsController's cache for this parent.
6. Return to the first Parent children screen and tap at the Child. This will allow you to change parent of the child. Tap other parent.
7. Navigate to the second Parent children' screen.

Expected Results:
Second Parent' screen should display Child moved from first Parent. I've read the Core Data documentation and found no mention of such behaviour. Thus considering it's a bug.

Actual Results:
Second Parent' screen displays nothing.

Additional Information:
Bug will not reproduce if you:
— don't save context after changing the parent (see. `UpdateParentViewController.m:86`)
— don't use NSFetchedResultsController's cache

I've checked underlying SQLite database and it contains all updates I made with child.

Version/Build:
Version 10.0 (10A255), iOS 12 SDK

Configuration:
N/A

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!