如何使用MagicalRecord设置Core Data轻量级迁移?
我尝试使用MagicalRecord来设置Core Data的轻量级迁移。 我已经使用Google和SO查看了关于这个主题的所有post。 我了解persistentStoreCoordinator是如何工作的,以及我想要做的设置。
这是我的代码:
AppDeligate.h
NSPersistentStoreCoordinator *persistentStoreCoordinator;
AppDelegate.m
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"saori.sqlite"]]; // handle db upgrade NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) { // Handle error } return persistentStoreCoordinator;
}
我收到以下错误,我明白了; 我不知道的是这些对象在哪里(我看了我的应用程序,什么都没find):
'AppDelegate'没有可见的@interface声明select器'applicationDocumentsDirectory'和
'AppDelegate'没有可见的@interface声明select器'managedObjectModel'
我已经创build了商店:
如果不是我所看到的大部分代码都是相似的, 我不知道MagicalRecord是否为我处理这个问题,因为我找不到任何可以指示如何使用MR的文档。 我的问题是:我需要做些什么才能做到这一点?
MagicalRecord的全部要点是,这是为你pipe理的:
[MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreNamed:####];
在这里查看关于核心数据堆栈设置的文档。
确保你检查所有这些东西:
在您的AppDelegate.m文件中:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { ... [MagicalRecord setupAutoMigratingCoreDataStack]; ... }
如果您还没有版本化您的模型:
- select你的数据模型
-
编辑器 – >添加模型版本
-
命名新版本,完成
- 现在应该有两个版本。 如图所示select文件。
- 将模型版本更改为新版本
- 新版本应该现在检查
至于我对这个问题的理解,我build议你使用这个
[MagicalRecord setupAutoMigratingCoreDataStack]
如果尚未更改模型版本,请将其更改为使用旧模型创build的新模型
- 核心数据示例,无效更新:部分0中的行数无效
- 有没有可用于iOS的数据绑定机制?
- 将核心数据添加到实体
- NSManagedObject的描述显示值,但访问它们显示NaN?
- 如何使用当前的NSPersistentStore方法在本地和iCloud中创build可共享的Core Data .sqlite备份
- 在核心数据的一对多关系中,存储的数据无法显示在表格视图中?
- NSFetchedResultsController与UILocalizedIndexedCollation
- 撤消核心数据pipe理对象
- iOS的崩溃'NSInternalInconsistencyException',原因:'语句仍然是'核心数据caching相关?