Custom Policy in my xcmappingmodel will not be executed
Asked Answered
P

2

4

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?

Pot answered 22/6, 2011 at 15:2 Comment(0)
D
4

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.

Domineering answered 24/6, 2011 at 20:52 Comment(3)
Okay, didn't know that. Actually that may be the problem, since we want to leverage the migration mechanism to improve an underlying directory structure (each record has a file that needs to be renamed for convenience). Since there are no real model changes is there a way to force the migration? Or do I have to add one imaginary field and then remove it with another migration?Pot
This may be the problem. Adding an imaginary field may solve your problem. This at least should trigger your mapping.Domineering
This was the problem! Thanks for helping.Pot
T
3

NSInferMappingModelAutomaticallyOption should be set to NO.

Also, if the model isn't different, you can set the Version Hash Modifier in the Entity inspector. Then Core Data will recognize the model as being different:

https://developer.apple.com/library/mac/documentation/cocoa/conceptual/CoreDataVersioning/Articles/vmUnderstandingVersions.html

Tenpin answered 31/12, 2013 at 2:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.