Skip to content

Instantly share code, notes, and snippets.

@dmytro-anokhin
Last active August 15, 2019 13:49
Show Gist options
  • Select an option

  • Save dmytro-anokhin/dda6b5ec0e58d4370a3e65b7f35b5d25 to your computer and use it in GitHub Desktop.

Select an option

Save dmytro-anokhin/dda6b5ec0e58d4370a3e65b7f35b5d25 to your computer and use it in GitHub Desktop.
let modelDescription = CoreDataModelDescription(
entities: [
.entity(
name: "Author",
managedObjectClass: Author.self,
attributes: [
.attribute(name: "name", type: .stringAttributeType)
],
relationships: [
.relationship(name: "publications", destination: "Publication", toMany: true, deleteRule: .cascadeDeleteRule, inverse: "author")
]),
.entity(
name: "Publication",
managedObjectClass: Publication.self,
attributes: [
.attribute(name: "publicationDate", type: .dateAttributeType),
.attribute(name: "numberOfViews", type: .integer64AttributeType, isOptional: true)
],
relationships: [
.relationship(name: "author", destination: "Author", toMany: false, inverse: "publications")
]),
.entity(
name: "Article",
managedObjectClass: Article.self,
parentEntity: "Publication",
attributes: [
.attribute(name: "text", type: .stringAttributeType)
])
]
)
let model = modelDescription.makeMode()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment