How to switch from Core Data automatic lightweight migration to manual?
Posted
by Jaanus
on Stack Overflow
See other posts from Stack Overflow
or by Jaanus
Published on 2010-04-16T16:02:54Z
Indexed on
2010/04/16
16:43 UTC
Read the original article
Hit count: 369
My situation is similar to this question. I am using lightweight migration with the following code, fairly vanilla from Apple docs and other SO threads. It runs upon app startup when initializing the Core Data stack.
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
NSError *error = nil;
NSString *storeType = nil;
if (USE_SQLITE) { // app configuration
storeType = NSSQLiteStoreType;
} else {
storeType = NSBinaryStoreType;
}
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
// the following line sometimes crashes on app startup
if (![persistentStoreCoordinator addPersistentStoreWithType:storeType configuration:nil URL:[self persistentStoreURL] options:options error:&error]) {
// handle the error
}
For some users, especially with slower devices, I have crashes confirmed by logs at the indicated line.
I understand that a fix is to switch this to manual mapping and migration. What is the recipe to do that? The long way for me would be to go through all Apple docs, but I don't recall there being good examples and tutorials specifically for schema migration.
© Stack Overflow or respective owner