NSFetchedResultsController grouping fails with saved child contexts

I have a basic stack, with a main queue root context and a main queue scratch context while the user is editing.


If I use an NSFetchedResultsController to fetch from the child context after it's saved, the controller always returns 0 sections. It works fine if the child context hasn't been saved yet, or if the NSFetchedResultsController targets the root context. I've opened a bug report with Apple #21889387 but it's blocking me in a production app, so if anyone can help, that'd be great!


I've created a unit test file that demonstrates the error here https://github.com/adly-holler/frc-child-context-bug


Thanks in advance!

You need to save the main context (your rootCtx) after saving your child context, in order for the fetchedResultsController to refresh it's sections.


No - I don't know why either. I suspect that these are not calculated until the data hits the persistent store. They are probably implemented in SQL with a GROUP BY query or something...

NSFetchedResultsController grouping fails with saved child contexts
 
 
Q