Core data 使用MagicalRecord手动迁移

Core data 使用MagicalRecord手动迁移,core-data,migration,magicalrecord,Core Data,Migration,Magicalrecord,我正在实现CoreData存储的迁移,在这里我用BOOL属性替换字符串属性:当字符串为“0”时,BOOL应该是“YES”,在所有其他情况下,BOOL应该是“NO”。听起来很简单,但我认为我仍然需要添加一个映射模型。我在Xcode中添加了它,并实现了createDestinationInstancesForSourceInstance: - (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance

我正在实现CoreData存储的迁移,在这里我用BOOL属性替换字符串属性:当字符串为“0”时,BOOL应该是“YES”,在所有其他情况下,BOOL应该是“NO”。听起来很简单,但我认为我仍然需要添加一个映射模型。我在Xcode中添加了它,并实现了
createDestinationInstancesForSourceInstance

- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance entityMapping: (NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error
{
   NSManagedObject *newObject = [NSEntityDescription insertNewObjectForEntityForName:[mapping destinationEntityName] inManagedObjectContext:[manager destinationContext]];

   NSString *oldValue = [sInstance valueForKey: @"oldString"];
   NSNumber *newValue = @(NO);

   if ([oldValue integerValue] == 0)
      newValue = @(YES);

   [newObject setValue: newValue forKey: @"newBool"];

   [manager associateSourceInstance:sInstance withDestinationInstance:newObject forEntityMapping:mapping];

   return YES;
}
然而,这从未被调用

因为我在使用MagicalRecord,所以我也在使用:

[MagicalRecord SetupCoreDataStackWithAutoMigratingSqliteStoreName:@“storename.sqlite”]

我读到我还需要使用:
NSDictionary*options=@{NSMigratePersistentStoresAutomaticallyOption:@(是),NSInferMappingModelAutomaticallyOption:@(否)}当我初始化我的商店时,但如何将其与MagicalRecord一起使用


更新:因此MR使用
MR_自动迁移选项
设置迁移选项。有没有办法修改这些文件以支持手动迁移?

要执行手动迁移,您需要使用:


[MagicalRecord设置手动迁移StackwithSqliteStoreName:@“storename.sqlite”]

我在MR中没有,您使用的是哪个版本?这是一个未发布的版本,我很犹豫是否要使用它。不过还是要谢谢你。值得的是,我已经用了几个月了,它很结实。话虽如此,我还没有尝试过手动迁移堆栈。蒂姆·罗德利(Tim Roadley)的一本关于CoreData for iOS的优秀新书促使我在本周末(在你今天回答之前)实际上决定暂时不使用MR。我强迫自己通过直接与核心数据交互而不是通过框架来更好地理解核心数据。一旦我更好地理解了它,我可能会再次向先生致谢,感谢你的洞察力。