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?
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 =/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With