我想從一個.xcdatamodel文件遷移到另一個。我有一個NSEntityMigrationPolicy子類,其名稱已在xcode-> .xcmappingmodel文件 - >實體 - >「自定義策略」字段中輸入。NSEntityMigrationPolicy子類方法不被調用
我運行我的應用程序,它成功地打開並運行我的數據的以前版本,所以我只能假設基本的遷移工作。但是我的NSEntityMigrationPolicy子類方法沒有被調用,所以我可以運行進一步的遷移代碼。
@implementation TestMigrationPolicy
- (BOOL)beginEntityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError * *)error
{
NSLog(@"this log is never shown!!!!");
return YES;
}
有沒有人有任何想法,爲什麼我可能不會被叫?我是核心數據遷移的新手,我目前不知道爲什麼這不像我認爲的那樣行事。
如果有幫助,我創建的持久性存儲這樣的..
NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:YES],
NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES],
NSInferMappingModelAutomaticallyOption,
nil];
NSError *error = nil;
persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
NSLog(@"storeUrl %@", storeUrl);
if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) {
啊,這很酷,謝謝! ...但是如果我也想要自動映射發生呢?所以,我在模型版本16上。我想要從15到16的手動遷移,但以前的遷移可以是自動的。 – Benjohn 2017-02-04 22:51:10