Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Core Data : Post migration, additional migration code

I wish to migrate from my version1 data model to version2, but once the migration is complete I wish to perform some custom migration code. How will I know if/when the migration occurs? Is there a migrationHasCompleed delegate method or notification?

For interests sake: The custom migration code I wish to perform resizes png's in the database.

like image 445
user139816 Avatar asked Feb 16 '26 04:02

user139816


1 Answers

For reference, you can also test in advance whether a migration is necessary, which would probably be cleaner.

NSError *error;
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType
                                                                                          URL:storeURL
                                                                                        error:&error];
NSManagedObjectModel *destinationModel = [persistentStoreCoordinator managedObjectModel];
BOOL migrationRequired = ![destinationModel isConfiguration:nil compatibleWithStoreMetadata:sourceMetadata];

// Now add persistent store with auto migration, and do the custom processing after
like image 56
Michael Tyson Avatar answered Feb 19 '26 02:02

Michael Tyson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!