How to migrate in CoreData a NSSet to NSOrderedSet?

In my CoreData model I have a to-many-relation defined. I like to sort the items in the relation by a date property and to migrate to a NSOrderedSet.


Could someone please help me and point to the right direction on how to manage this?

Answered by devfcr in 19982022

After looking more around on this issue it turned out,

that coredata lightweight migration is fully capable to turn a NSSet based relation to a NSOrderedSet based relation.


After migration all items in the NSOrderedSet based relation are in arbitrary order.

To bring the data objects into right order a post migration step is necessary, which will only be executed once after the migration process.

I found a good example on how to do this in the WWDC 2010 Session "Mastering Core Data" at the very end of the video (51:50).

Did you have any specific questions about the contents of the Core Data Model Versioning and Data Migration Programming Guide?


It sounds like you're pretty much going to be locked into the three stage migration process, and you're going to be needing to do work in step 2:

Recreate relationships.At the beginning of this phase, the entity migration policy is sent a

createRelationshipsForDestinationInstance:entityMapping:manager:error:
message; at the end it is sent a
endRelationshipCreationForEntityMapping:manager:error:
message.For each entity mapping (in order), for each destination instance created in the first step any relationships are recreated.
Accepted Answer

After looking more around on this issue it turned out,

that coredata lightweight migration is fully capable to turn a NSSet based relation to a NSOrderedSet based relation.


After migration all items in the NSOrderedSet based relation are in arbitrary order.

To bring the data objects into right order a post migration step is necessary, which will only be executed once after the migration process.

I found a good example on how to do this in the WWDC 2010 Session "Mastering Core Data" at the very end of the video (51:50).

How to migrate in CoreData a NSSet to NSOrderedSet?
 
 
Q