Re: Core Date migration


Dave Fernandes
 

If you are modifying the object, I believe you should be doing this in:
createDestinationInstances(forSource:in:manager:)

This has always worked for me. The validation method looks like a keep/don’t keep decision point, though I have never used it.


On Jul 22, 2019, at 11:56 AM, Steve Mills via Groups.Io <sjmills@...> wrote:

In my Core Data model, I've added a 2nd version with a new attribute. This attribute needs to be initialized to a sequential value upon migration from the old version. So I'm using a mapping model and a custom migration policy to set this new attribute's value on every entity object.

But, it's not sticking. Do I need to be doing something else in my performCustomValidationForEntityMapping:manager:error: method to cause the changes I've made to be saved? Or am I just interpreting the incredibly vague documentation for this method wrong?

-(BOOL) performCustomValidationForEntityMapping:(NSEntityMapping*)mapping manager:(NSMigrationManager*)manager error:(NSError* _Nullable __autoreleasing*)error
{
BOOL result = YES;

if([manager isKindOfClass:[DocumentMigrationManager class]]) {
Document* doc = ((DocumentMigrationManager*)manager).doc;
NSFetchRequest* fetchRequest = [NSFetchRequest new];
NSEntityDescription* assetEntDesc = [Asset entityInManagedObjectContext:manager.destinationContext];

fetchRequest.entity = assetEntDesc;

NSArray<Asset*>* asses = [manager.destinationContext executeFetchRequest:fetchRequest error:error];

for(Asset* ass in asses) {
// ass.order = @(doc.nextAssetOrder);
[ass setValue:@(doc.nextAssetOrder) forKey:AssetAttributes.order];
}
}

return result;
}

(And damn it, when is Mail going to let us change to 4 spaces per tab like *normal* people use? My radar for that has been ignored for years.)

--
Steve Mills
Drummer, Mac geek





Join {cocoa@apple-dev.groups.io to automatically receive all group messages.