ManagedModels icon indicating copy to clipboard operation
ManagedModels copied to clipboard

Always pre-fill the metadata property info slot

Open helje5 opened this issue 2 years ago • 0 comments

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.

helje5 avatar Oct 21 '23 13:10 helje5