Search code examples
iphonecore-datamigrationmapping-model

iPhone core data migration date to string


I have an entity that originally started with a date attribute. I have now added a attribute that is a string that I want to hold the date, in addition to keeping the original field. I've made a mapping model, but I'm not sure what to put into "value expression" to get the new string field filled with data from the date field in the format "2010-10-25" during migration.

Any help would be appreciated.

Also I need it to be a real attribute not a transient because I want to sort on it. I didn't realize you couldn't sort on transient attribute until too late.


Solution

  • Translating the property from a date to a string is going to require that you build your own NSEntityMigrationPolicy for that migration and override the -createDestinationInstancesForSourceInstance: entityMapping: manager: error: method to handle the translation.

    This should be very straight forward code since you are only going to be manipulating a couple of properties and the entity mapping is still one to one.