1

I've done a custom Core Data migration several versions back when doing some structure changes in my app. (So created a new model version, and a mapping model with custom policy class).

Now, I want to do some more changes. So I've created another model version. Now, I'm not sure whether I need to create another mapping model for this change? If I do, will core data just figure out the appropriate one to use based on the users version?

Will I also need to create another custom policy class, or can I somehow add the new logic to the first one?

Lastly, will I need to add any logic for migrating from the original database straight to the current database? Or will core data figure that out for me, and migrate to the median version first, and then to the current version when a user loads an app version with the original data structure?

Thanks!

4

2 回答 2

0

根据您的模型更改,您可以使用“默认迁移过程”。调用时addPersistentStoreWithType:configuration:URL:options:error:,使用标志NSMigratePersistentStoresAutomaticallyOption

此外,我确信不幸的是,您需要为每个可能的迁移使用一个映射模型。如果您有 3 个模型,则必须实现:1 到 3 和 2 到 3。Core Data 不够聪明,无法自动执行中间步骤:(

于 2013-08-26T04:26:56.930 回答
0

我猜你是否需要创建另一个映射模型的答案是......这取决于。在此处查看 Apple 的文档(特别是关于轻量级迁移的评论):https ://developer.apple.com/library/ios/documentation/cocoa/Conceptual/CoreDataVersioning/Articles/vmMigrationProcess.html#//apple_ref/doc/uid/TP40004399- CH6-SW1

于 2013-08-26T04:27:03.290 回答