How to auto generate NSManagedObject subclasses with date attribute as Date instead of NSDate?

馋奶兔 提交于 2019-12-19 17:33:06

问题


I'm currently updating my project to Swift 3 and I'm moving all my NSDate methods and extensions to Date in order to keep the standard in the app.

The problem is that I use Xcode to auto-generate my NSManagedObject subclasses and it is generating the date attributes as NSDate instead of Date.

Is there a way to generate it with the date attributes as Date?

EDIT

Per Apple Developer Documentation:

Core Data natively supports a variety of attribute types, such as string, date, and integer (represented as instances of NSString, NSDate and NSNumber respectively).

So I think it's not possible =/


回答1:


It's not currently possible, because Core Data is still very much tied to Objective-C types, and this is one of the places it shows.

However, you can still assign a Date to an NSDate attribute:

    newEvent.timestamp = Date() as NSDate

It's far from ideal, but if you have other code that uses Date, you don't have to make it use NSDate instead. Use as to convert only when working directly with your managed objects.



来源:https://stackoverflow.com/questions/40853624/how-to-auto-generate-nsmanagedobject-subclasses-with-date-attribute-as-date-inst

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!