本文介绍了如何自动生成日期属性为Date而不是NSDate的NSManagedObject子类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在将我的项目更新为Swift 3,并且我将所有的NSDate方法和扩展都移到了Date,以便在应用程序中保持标准。

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.

问题是我使用Xcode自动生成我的NSManagedObject子类,它生成日期属性为NSDate而不是Date。

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?

每 :

所以我认为这不可能= /

So I think it's not possible =/

推荐答案

事实并非如此目前可能,因为Core Data仍然与Objective-C类型密切相关,这是它显示的地方之一。

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.

但是,你仍然可以分配一个日期 NSDate 属性:

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

    newEvent.timestamp = Date() as NSDate

这远非理想,但如果你有其他代码使用日期,你不必使用 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.

这篇关于如何自动生成日期属性为Date而不是NSDate的NSManagedObject子类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 22:58