I’m using Core Data to persist some information in a SQLite database. I’m testing with the simulator, and using sqlite3 to query the database and verify that I’m storing what I expect.
What I’m seeing is that the data doesn’t appear in the SQLite database until a good 15-20 seconds after I’ve saved it.
Here’s the code that I’ve cut my save down to:
NSEntityDescription *customerType = [NSEntityDescription entityForName:@"CustomerType" inManagedObjectContext:context];
CustomerType *ct = [[CustomerType alloc]initWithEntity:customerType insertIntoManagedObjectContext:context ];
ct.code = code;
NSError* error = nil;
if (![context save:&error] || error)
NSLog(@"Saved new customer (error=%@)", [error debugDescription]);
The save operation completes without error.
Any hints as to why I’m seeing this delay? Is my save operation not running properly, or is the delay in persisting the data an artifact of the simulator?
Solution!
I create the
NSManagedObjectContextvia aUIManagedDocument. To persist the data in a timely manner I need to save the managed document, not just save the changes I’ve made to the object graph in the managed object context.