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

I am currently upgrading my project to Swift 3, and I am moving all of my methods and NSDate extensions to Date to keep the standard in the application.

The problem is that I use Xcode to automatically subclass NSManagedObject and generate date attributes as NSDate instead of Date.

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

EDIT

Per Apple Developer Documentation :

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

So I think this is not possible = /

+7
ios swift3 nsdate core-data nsmanagedobject
source share
1 answer

This is currently not possible, because Core Data is still very attached to Objective-C types, and this is one of the places it shows.

However, you can still assign Date to the NSDate attribute:

  newEvent.timestamp = Date() as NSDate 

This is far from ideal, but if you have other code that uses Date , you do not need to use its NSDate . Use as to convert only when working with your managed objects.

+1
source share

All Articles