@NSManaged变量必须是可选的吗?

时间:2015-11-17 14:01:33

标签: swift core-data nsmanagedobject

在Xcode 7中,自动生成的核心数据类将核心数据变量放在单独文件的扩展名中。它们还使每个变量都可选。我理解为此的一些推理,核心数据对象没有swift init函数。如何知道变量永远不会是零?

但是,我在override func awakeFromInsert()内分配了几个变量。一旦创建/插入它们,它们就具有非可选值。这些变量在核心数据模型中也设置为不可选。有没有理由我不应该在扩展名中将这些变量更改为非可选项?

此外,如果@NSManaged var bioRatio: NSNumber?核心数据模型中的属性值为Integer 32,我是否有理由在扩展名中将其声明为@NSManaged var bioRatio: Int

extension ShoppingItems {

    @NSManaged var bioRatio: NSNumber?
    @NSManaged var dateCreated: NSDate?
    @NSManaged var dateModified: NSDate?
    @NSManaged var dateSynced: NSDate?
    @NSManaged var coreDiesel: NSNumber?
    @NSManaged var coreHaveStock: NSNumber?
    @NSManaged var coreMonthlyStock: NSNumber?
    @NSManaged var myName: String?
    @NSManaged var recordChangeTag: String?
    @NSManaged var stdQty: NSNumber?
    @NSManaged var urgency: NSNumber?
    @NSManaged var uuidAccount: String?
    @NSManaged var uuidFamily: String?
    @NSManaged var uuidKey: String?
    @NSManaged var uuidUnit: String?
    @NSManaged var uuidUser: String?
    @NSManaged var myAccount: Accounts?
    @NSManaged var coreMyCategoryLinks: NSSet?
    @NSManaged var coreMyPackageHistories: NSSet?
    @NSManaged var coreMyPackages: NSSet?
    @NSManaged var myUnit: Units?

}

0 个答案:

没有答案