Re: Core Date migration


Steve Mills
 

On Jul 23, 2019, at 12:54:04, Jim <jimcfl@...> wrote:

Do you call save on the context somewhere? I’ve not needed to use a mapping like this yet but it seems like if you’re changing attributes you’d want to save.
No, I wasn't sure if that was necessary. One would hope that the act of migration will save the migrated data to the store without the developer having to do anything. It doesn't say that in the migration doc. In fact, it says it's part of the default migration process:

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/CoreDataVersioning/Articles/vmMigrationProcess.html#//apple_ref/doc/uid/TP40004399-CH6-SW8

I've also gone the "normal" route of creating the new objects in configurePersistentStoreCoordinatorForURL:ofType:modelConfiguration:storeOptions:error: and setting the new attribute's value there. Both ways work at that point in the migration, but then when addPersistentStoreWithType:configuration:URL:options:error: is called at the end, it once again goes through another migration that I expect would happen. My custom migration policy is created out of my control, so I can't set a custom property on it, nor can I add an object to any object's userInfo (NSEntityMapping, NSMigrationManager, etc). I need to be able to get back to my document from the migration policy, and I can't find a way to do that when the default migration happens. If I could, then I don't think I'd need to do the manual migration at all.

--
Steve Mills
Drummer, Mac geek

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