Skip to content
Declarative way to describe a Core Data model in code.
Branch: master
Clone or download
dmytro-anokhin Merge pull request #3 from vander2675/master
Relationship NSDelteRule was not getting set
Latest commit 47ea087 Aug 22, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
Sources/CoreDataModelDescription Relationship NSDelteRule now actually gets set on NSRelationShipDescr… Aug 22, 2019
Tests Added Configurations Aug 19, 2019
.gitignore Update gitignore Aug 13, 2019
Package.swift Initial Commit Aug 12, 2019 Update Aug 15, 2019


Declarative way to describe a Core Data model in code.


Use CoreDataModelDescription to describe your model. Sample code describes this model:

Image of Author, Publication, and Article model

Assuming you already defined Author, Publication, and Article subclasses of NSManagedObject.

let modelDescription = CoreDataModelDescription(
    entities: [
            name: "Author",
            managedObjectClass: Author.self,
            attributes: [
                .attribute(name: "name", type: .stringAttributeType)
            relationships: [
                .relationship(name: "publications", destination: "Publication", toMany: true, deleteRule: .cascadeDeleteRule, inverse: "author")
            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")
            name: "Article",
            managedObjectClass: Article.self,
            parentEntity: "Publication",
            attributes: [
                .attribute(name: "text", type: .stringAttributeType)

let model = modelDescription.makeModel()


Motivation and creating this package described in my article Core Data and Swift Package Manager.

You can’t perform that action at this time.