I’m using a secondary managedobjectcontext in a serial GCD queue, using the same persistent store coordinator (and model). The problem I am having is the secondary managedobjectmodel appears to be empty – all fetch requests return nothing. I am using a sqlite store. I’ve tried doing the same thing on the main thread to no avail.
The code is pretty straightforward. The CoreDataUtility is a singleton, and the manageObjectContext member of the singleton is the other managed object context.
NSManagedObjectContext *managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator:[CoreDataUtility instance].managedObjectContext.persistentStoreCoordinator];
The fetch requests (I’ve tried several) are identical with the exception of the mom.
The secondary mom looks fine in the debugger – the properties you would expect to be the same in the primary mom are in fact the same.
The problem turned out to be with the way I was loading the model. I don’t have an explanation as to why this worked, but it did fix the problem. Maybe someone else can elucidate.
This code:
was replaced with this code: