首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >未调用的NSEntityMigrationPolicy子类方法

未调用的NSEntityMigrationPolicy子类方法
EN

Stack Overflow用户
提问于 2010-09-06 21:25:40
回答 2查看 2.4K关注 0票数 3

我正在尝试从一个.xcdatamodel文件迁移到另一个文件。我有一个NSEntityMigrationPolicy子类,我已经在xcode-> .xcmappingmodel file -> entity -> "custom Policy“字段中输入了它的名称。

我运行我的应用程序,它成功地打开并运行了我的数据的前一个版本,所以我只能假设基本迁移已经起作用了。但是,我的NSEntityMigrationPolicy子类方法没有被调用,因此我可以运行进一步的迁移代码。

代码语言:javascript
运行
复制
@implementation TestMigrationPolicy

- (BOOL)beginEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError * *)error
{
    NSLog(@"this log is never shown!!!!");
    return YES;
}

有没有人知道为什么我的it不会被调用?我是核心数据迁移的新手,目前我对为什么这不是我觉得应该的行为感到困惑。

如果有帮助,我正在创建持久存储,如下所示。

代码语言:javascript
运行
复制
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                         [NSNumber numberWithBool:YES], 
                         NSMigratePersistentStoresAutomaticallyOption,
                         [NSNumber numberWithBool:YES],
                         NSInferMappingModelAutomaticallyOption,
                         nil];


NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSLog(@"storeUrl  %@", storeUrl);

if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
EN

Stack Overflow用户

回答已采纳

发布于 2013-03-26 02:45:12

我知道这个问题有点老了,但这可能会对其他人有所帮助!

这是因为您设置了选项NSInferMappingModelAutomaticallyOption -这意味着正在运行轻量级迁移,而不是使用您的映射模型。删除此选项,保留* NSMigratePersistentStoresAutomaticallyOption*,所有选项都将正常工作。

票数 5
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3651805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档