【发布时间】:2014-03-03 23:42:35
【问题描述】:
我正在实现我的 CoreData 存储的迁移,其中我将字符串属性替换为 BOOL 属性:当字符串为“0”时,布尔值应为“YES”,在所有其他情况下,布尔值应为“不”。听起来很简单,但我想我仍然需要添加一个映射模型。我在 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 setupCoreDataStackWithAutoMigratingSqliteStoreNamed: @"storename.sqlite"];
我读到我还需要在初始化商店时使用:NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption: @(YES), NSInferMappingModelAutomaticallyOption: @(NO)};,但是如何将它与 MagicalRecord 一起使用?
更新:所以 MR 使用MR_autoMigrationOptions 来设置迁移选项。有没有办法修改这些以支持手动迁移?
【问题讨论】:
标签: core-data migration magicalrecord