Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cypherpoet/coredatakit

A collection of utilities for building Core Data applications in SwiftUI.
https://github.com/cypherpoet/coredatakit

coredata coredata-swiftui swift-packages swiftui xcode

Last synced: 1 day ago
JSON representation

A collection of utilities for building Core Data applications in SwiftUI.

Awesome Lists containing this project

README

        

# CoreData Kit


CypherPoetCoreDataKit Header Image














Twitter: @cypher_poet

_A collection of utilities for building Core Data-backed applications in Swift._

## 🚧 Disclaimer

This library is still very much a WIP as I study/experiment with/develop best practices, patterns, and affordances for Core Data after the releases of Swift 5.5 and "SwiftUI 3.0". Please treat it as a guideline/reference for the time being 🙂.

## Features

- ✅ A [`CoreDataManager`](./Sources/CoreDataManager/) that handles setting up a ["Core Data Stack"](https://developer.apple.com/documentation/coredata/core_data_stack).
- ✅ A [`rich set of utilities`](./Sources/Migration/) for performing Core Data migrations.
- ✅ A [`FetchedResultsControlling` protocol](./Sources/FetchUtils/FetchedResultsControlling.swift) that helps architect `NSFetchedResultsController` instances and extract data from their `NSFetchRequest` results.
- ✅ Utilities for composing `NSPredicate` instances in a strongly-typed fashion.
- ✅ Strongly-typed errors under types like `CoreDataManager`, `PersistentStoreMigrator` and more.
- ✅ `NSPersistentStore` helpers for using different SQLite writing locations in development and production.

## Installation

### Xcode Projects

Select `File` -> `Swift Packages` -> `Add Package Dependency` and enter `https://github.com/CypherPoet/CypherPoetCoreDataKit`.

### Swift Package Manager Projects

You can add this project as a package dependency in your `Package.swift` file:

```swift
let package = Package(
//...
dependencies: [
.package(
url: "https://github.com/CypherPoet/CoreDataKit",
.exact("0.0.21")
),
],
//...
)
```

From there, refer to the `CoreDataKit` "product" delivered by the `CypherPoetCoreDataKit` "package" inside of any of your project's target dependencies:

```swift
targets: [
.target(
name: "YourLibrary",
dependencies: [
.product(name: "CoreDataKit", package: "CypherPoetCoreDataKit"),
],
...
),
...
]
```

Then simply `import CoreDataKit` wherever you’d like to use it.

## Usage

Currently, usage of these utilities is best demonstrated by the various example applications [here](./Examples/). But a few pointers...

### Dynamically initializing a Core Data Stack for your app depending on whether it's running for production or for Xcode Previews.

- [🔗 Example](https://github.com/CypherPoet/CoreDataKit/blob/migration-helpers/Examples/ReviewJournal/Shared/Misc%20Utils/Extensions/CoreDataManager%2BUtils.swift)

### Setting up the Core Data stack on launch

- [🔗 iOS Example](./Examples/ReviewJournal/iOS/App/AppDelegate.swift)
- [🔗 macOS Example](./Examples/ReviewJournal/macOS/App/AppDelegate.swift)

### Core Data Migrations

- [🔗 Example application built specifically around this.](./Examples/ReviewJournal)

### Requirements

- Xcode 13.0+ (Recommended)

### 📜 Generating Documentation

Documentation is generated by [Swift Doc](https://github.com/SwiftDocOrg/swift-doc). Installation instructions can be found [here](https://github.com/SwiftDocOrg/swift-doc#installation), and as soon as you have it set up, docs can be generated simply by running `./Scripts/generate-html-docs.zsh` from the command line.

📝 Note that this will only generate a `.build/documentation` folder for you to view locally. This folder is being ignored by `git`, and a GitHub [action](./.github/workflows/PublishDocumentation.yml) exists to automatically generate docs at the root level and serve them on the project's `gh-pages` branch.

## 🏷 License

`CypherPoetCoreDataKit` is available under the MIT license. See the [LICENSE file](./LICENSE) for more info.