【发布时间】:2010-12-10 10:41:49
【问题描述】:
我想将一个 sqlite 文件(使用带有模型 A 的 Core Data 创建的)中的内容附加到我的应用程序使用的另一个 sqlite 存储(它使用相同的模型 A)。这个想法是快速导入大量数据。
我面临的问题是下面的代码只能运行一次。当我尝试两次运行相同的代码时,应用程序将在我用我的注释标记的行中崩溃。任何帮助将不胜感激。
NSError **err;
NSURL *importURL = [NSURL fileURLWithPath:[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: @"import.sqlite"]];
NSURL *storeURL = [NSURL fileURLWithPath:[[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"applicationdata.sqlite"]];
NSMigrationManager *migrator = [[NSMigrationManager alloc] initWithSourceModel:[self managedObjectModel] destinationModel:[self managedObjectModel]];
NSMappingModel *mappingModel = [NSMappingModel inferredMappingModelForSourceModel:[self managedObjectModel] destinationModel:[self managedObjectModel] error:err];
NSError **err2;
// the following line crashes when the whole block is ran twice
[migrator migrateStoreFromURL:importURL
type:NSSQLiteStoreType
options:nil
withMappingModel:mappingModel
toDestinationURL:storeURL
destinationType:NSSQLiteStoreType
destinationOptions:nil
error:err2];
NSLog(@"import finished");
[migrator release];
【问题讨论】:
标签: cocoa sqlite core-data migration