我希望从版本 1 数据模型迁移到版本 2,但迁移完成后我希望执行一些自定义迁移代码。我如何知道迁移是否/何时发生?是否有migrationHasCompleed委托方法或通知?
为了兴趣:我希望执行调整数据库中 png 大小的自定义迁移代码。
作为参考,您也可以提前测试是否需要迁移,这样可能会更干净。
NSError *error;
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType
URL:storeURL
error:&error;];
NSManagedObjectModel *destinationModel = [persistentStoreCoordinator managedObjectModel];
BOOL migrationRequired = ![destinationModel isConfiguration:nil compatibleWithStoreMetadata:sourceMetadata];
// Now add persistent store with auto migration, and do the custom processing after
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)