我希望你能帮助我。我有三个模型版本 V1、V2 和 V3(当前模型)。因此,我有两个映射模型 V1to2 V2to3 我还启用了 NSMigratePersistentStoresAutomaticallyOption。
当我使用 V2 商店启动我的应用程序时,它会成功迁移到 V3。但是当我使用 V1 商店启动我的应用程序时,应用程序崩溃了,因为没有找到映射模型:
NSDictionary *optionsDictionary = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:NSMigratePersistentStoresAutomaticallyOption];
if (![psc addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:storeURL
options:optionsDictionary
error:&error]) {
[NSexception raise:@"Open failed" format:@"Reason: %@", [error localizedDescription]];
}
我试图将当前模型更改为 V2 并且它可以工作,它成功地从 V1 迁移到 V2。之后,我只是将当前模型改回 V3 并再次对应用程序进行分层,它成功地从 V2 迁移到 V3。
但是我做错了什么,这个迁移不会首先自动运行 V1toV2,然后自动运行 V2toV3?
非常感谢您的期待。弗洛