Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dmytro-anokhin/core-data-model-description
Declarative way to describe a Core Data model in code.
https://github.com/dmytro-anokhin/core-data-model-description
core-data coredata swift swift-package swift-package-manager swift5 xcode
Last synced: about 2 hours ago
JSON representation
Declarative way to describe a Core Data model in code.
- Host: GitHub
- URL: https://github.com/dmytro-anokhin/core-data-model-description
- Owner: dmytro-anokhin
- License: mit
- Created: 2019-08-13T18:59:30.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-17T08:40:55.000Z (about 3 years ago)
- Last Synced: 2024-10-13T16:17:42.953Z (25 days ago)
- Topics: core-data, coredata, swift, swift-package, swift-package-manager, swift5, xcode
- Language: Swift
- Homepage:
- Size: 43.9 KB
- Stars: 72
- Watchers: 5
- Forks: 9
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# CoreDataModelDescription
Declarative way to describe a Core Data model in code. Swifty Core Data model 🙂
## Usage
Use `CoreDataModelDescription` to describe your model. Sample code describes this model:
![Image of Author, Publication, and Article model](https://miro.medium.com/max/1400/1*j7NgD-RplJ13E6j1Lzao0A.png)
Assuming you already defined `Author`, `Publication`, and `Article` subclasses of `NSManagedObject`.
```swift
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", ordered: true)
]),
.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.makeModel()
```## Motivation
Motivation and creating this package described in my article [Core Data and Swift Package Manager](https://medium.com/@dmytro.anokhin/core-data-and-swift-package-manager-6ed9ff70921a).
This package is still on early stage of development. Please submit issues for missing functionality. Pull requests are more than welcome.