Swiftpack.co - ezoushen/Crush as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ezoushen.
ezoushen/Crush 0.10.1
Code with Core Data in a Swifty way
⭐ī¸ 32
🕓 1 week ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/ezoushen/Crush.git", from: "0.10.1")

Crush

Enhance the development experience with CoreData by providing greater type-safety and intuitive functionality

Overview

🕹ī¸ Take full control of your CoreData management.
🧑‍đŸ’ģ 100% managed code, no code generation required.
📖 Free from Xcode GUI, and human-friendly diff records on git.

Installation

Make sure you've declared Crush as your dependency before getting started

let package = Package(
  dependencies: [
    .package(
      url: "https://github.com/ezoushen/Crush",
      from: "TARGET_VERSION"
    ),
  ],
  targets: [
    .target(
      name: "<your-target-name>",
      dependencies: [
        "Crush"
      ]
    )
  ]
)

Usage

Only three steps to start using Crush

1. Define your schema

class Todo: Entity {
    @Required
    var title = Value.String("title") // A required string property named "title"

    @Optional
    var memo = Value.String("memo") // An optional string property named "memo"

    @Required
    @Default(false)
    var finished = Value.Bool("finished")

    @Optional
    var parent = Relation.ToOne<Todo>("parent") // An optional relationship to another Todo

    @Optional
    @Inverse(\.parent)
    var children = Relation.ToMany<Todo>("children")
}

2. Create your DataContainer

let container = try DataContainer.load(
    storages: .sqlite(url: targetURL), 
    dataModel: DataModel(name: "V1", [ Todo() ]))

3. Start coding đŸ”ĨđŸ”ĨđŸ”Ĩ

try container.startSession().sync { context in
    let todo = context.create(Todo.self)
    todo.title = "Hello Crush"
    try context.commit()
}

Documentation

Swift DocC style documentation is available here

Coorporation

If you want to contribute to the project, please feel free to open a pull request/issue.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics