I started using CoreData in my application after the Stanford CS193P tutorials regarding using iOS 5 of the new UIManagedDocument class. The approach itself is pretty simple, but I can't figure out how to deal with the modifications to the models that I continue to make. This is how I instantiate the UIManagedDocument object (inside appDelegate, so that every other class can use it):
if (!self.database) { NSURL *url=[[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; url = [url URLByAppendingPathComponent:@"AppName"]; UIManagedDocument *doc = [[UIManagedDocument alloc] initWithFileURL:url]; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; doc.persistentStoreOptions = options; self.database=doc; [doc release]; }
The problem is that every time I change at least a little of my .xcdatamodel, I canβt get all the contents previously saved in the document, as well as create any new instance. This actually throws the following exception:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'This NSPersistentStoreCoordinator has no persistent stores. It cannot perform a save operation.'
I thought that setting the "options" property of a managed document would solve the problem, but apparently this is not enough. Can anybody help? Could not find other questions that really fit my exact needs.
source share