我的xcmapping模型中的自定义策略将不会被执行 [英] Custom Policy in my xcmappingmodel will not be executed

查看:175
本文介绍了我的xcmapping模型中的自定义策略将不会被执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的应用程序创建一个具有一些自定义代码的映射模型。因此,我创建了一个xcmapping模型,我创建了一个NSEntityMigrationPolicy子类,并实现了

  createDestinationInstancesForSourceInstance 
pre>

方法。此外,我在我的映射模型中的自定义策略字段中输入了类名。不幸的是,我的代码永远不会被调用(试过断点和日志)。我的商店使用以下选项创建:

  NSMigratePersistentStoresAutomaticallyOption:YES 
NSInferMappingModelAutomaticallyOption:YES

我使用XCode 4.0.2(和XCode 4.2测试)。所有其他我的轻量级迁移运行顺利。

解决方案

您的模型版本有何不同? Core Data必须认识到存储与模型不兼容(表示为NSManagedObjectModel对象)。这是通过创建每个实体的属性的哈希值并散列这些值以表示每个实体的哈希值来完成的。如果这些值不改变,则不能区分模型。



有关数据模型更改所需的更多信息可以帮助您。


I'm trying to create a mapping model for my app that has some custom code. Thus I created a xcmappingmodel and I subclassed NSEntityMigrationPolicy and implemented the

createDestinationInstancesForSourceInstance

method. Further I entered the classname in the Custom Policy field in my mapping model. Unfortunately my code will never be called (tried breakpoints and logs). My store is created with the following options:

NSMigratePersistentStoresAutomaticallyOption: YES
NSInferMappingModelAutomaticallyOption: YES

I'm using XCode 4.0.2 (and tested with XCode 4.2 too). All other of my "lightweight" migrations are running smoothly. What do I need to do to get my custom migration running?

解决方案

How does your model versions differ? Core Data has to recognize that a store is not compatible with the model (represented as a NSManagedObjectModel object). This is done by creating hash values of the properties of each entity and hashing these values to represent a hash value for each entity. If those values do not change the models cannot be differentiated.

There is more information needed about the change in the data model to help you.

这篇关于我的xcmapping模型中的自定义策略将不会被执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆