Data-swift/ManagedModels

Figure out whether property initialisers _might_ be possible

helje5 opened this issue · 1 comments

@NSManaged doesn't allow this:

@Model class Item: NSManagedObject {
  var date = Date()
}

This complains that the @NSManaged var item must not have initialization expressions.

I don't think a macro can remove the expression, but maybe the property could be shadowed somehow. Which would also potentially help w/ Issue #2 .
I.e. instead of generating:

@NSManaged var date : Date

something more like:

var date = Date() {
  didSet { _date = newValue }
}
@objc(date)
@NSManaged var _date : Date

Potentially possible, not quite sure. That the _date is renamed might pose the biggest issue here.

Fixed in 0.6.0, initial values are now properly tracked in the metadata and can be picked up by the model generator.