CreateDestinationInstancesForSourceInstance is not called

I am trying to do custom migration to write CoreData. I need to change the name and type for the attribute.

So, I added a new data model and mappingmodel. For example, I have myData (String) in the old model, and I need CarDate (Date) in the new model. I added the line: CarDate => $ source.myData to the .xcmappingmodel file and created a class:

@implementation RemindersMigration

- (BOOL)createDestinationInstancesForSourceInstance:(NSManagedObject *)sInstance
                                  entityMapping:(NSEntityMapping *)mapping
                                        manager:(NSMigrationManager *)manager
                                          error:(NSError **)error {

NSManagedObject *newObject =
[NSEntityDescription insertNewObjectForEntityForName:[mapping destinationEntityName]
                              inManagedObjectContext:[manager destinationContext]];

NSString *dateString = [sInstance valueForKey:@"myData"];

NSDateFormatter *formatter = ...;

NSDate *date = [formatter dateFromString:dateString];

[newObject setValue:date forKey:@"CarDate"];

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

return YES;

}

I tested the migration using a simulator, so I switched to the old version using Git, added a new entry, switched to the new version. I have zero in CarDate. Please indicate to me where I am mistaken?

+4
source share
1 answer

" ", "" ( ) " " (alt + command + 3).

NSEntityMigrationPolicy ( RemindersMigration) " ".

enter image description here

+1

Source: https://habr.com/ru/post/1542220/


All Articles