iPhone核心数据迁移日期到字符串
我有一个最初以日期属性开头的实体。现在,除了保留原始字段之外,我还添加了一个属性,它是一个我想要保存日期的字符串。 我已经制作了一个映射模型,但我不确定在“值表达式”中放入什么内容,以便在迁移过程中用日期字段中的数据填充新的字符串字段,格式为“2010-10-25”。
任何帮助将不胜感激。
另外,我需要它是一个真实的属性而不是瞬态的,因为我想对其进行排序。我没有意识到你无法对瞬态属性进行排序,直到为时已晚。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将属性从日期转换为字符串需要您为该迁移构建自己的
NSEntityMigrationPolicy
并重写-createDestinationInstancesForSourceInstance:entityMapping: manager: error:
方法处理翻译。这应该是非常直接的代码,因为您只需要操作几个属性,并且实体映射仍然是一对一的。
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.