开发者

iPhone core data migration date to string

开发者 https://www.devze.com 2022-12-23 11:17 出处:网络
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 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号