2014-03-03 32 views
1

我正在實施CoreData存儲的遷移,在此我使用BOOL屬性替換字符串屬性:當字符串爲「0」時,布爾應該爲「YES」,並且在所有其他情況下布爾應該是「不」。聽起來很簡單,但我認爲我仍然需要添加一個映射模型。我補充說,在Xcode中,並實現createDestinationInstancesForSourceInstance使用MagicalRecord進行手動遷移

- (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來設置遷移選項。有沒有辦法修改這些以支持手動遷移?

回答

1

爲了執行手動遷移,您需要使用:

[MagicalRecord setupManuallyMigratingStackWithSQLiteStoreNamed: @"storename.sqlite"];

+0

,在MR,該版本是您使用我沒有? – Koen

+1

[MagicalRecord版本3](https://github.com/magicalpanda/MagicalRecord/tree/release/3.0) –

+1

這是一個未發佈的版本,我很猶豫使用它。不過謝謝。 – Koen