Data-swift / ManagedModels

A SwiftData like `@Model` infrastructure for CoreData.
https://www.alwaysrightinstitute.com/managedmodels/
Apache License 2.0
105 stars 5 forks source link

Always pre-fill the metadata property info slot #23

Open helje5 opened 1 year ago

helje5 commented 1 year ago

Sharing a whole entity hasn't been the best idea. But pre-creating the metadata info slots should always be possible. Of course inverse relationships won't usually be set as that requires the model resolution context.

E.g. this:

@Model class Person: NSManagedObject {
  var firstname : String
  var lastname : String
}

would generate sth like:

static let metadata = [
  ( "firstname", \Person.firstname, nil, nil ),
  ( "lastname", \Person.lastname, nil, nil )
]

(this is actually not true, this specific static type is detected by MM :-), but to illustrate the point). Instead we should do:

static let metadata = [
  ( "firstname", \Person.firstname, nil, makePropertyDescription(for: \Person.firstname) ),
  ( "lastname", \Person.lastname, nil, makePropertyDescription(for: \Person.firstname) )
]

The prototypes in the metadata are always copied already, before they are added to an entity.