Core Date migration

Steve Mills

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 { to automatically receive all group messages.