A collection of utilities for building Core Data-backed applications in Swift.
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 🙂.
- ✅ A
CoreDataManager
that handles setting up a "Core Data Stack". - ✅ A
rich set of utilities
for performing Core Data migrations. - ✅ A
FetchedResultsControlling
protocol that helps architectNSFetchedResultsController
instances and extract data from theirNSFetchRequest
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.
Select File
-> Swift Packages
-> Add Package Dependency
and enter https://github.com/CypherPoet/CypherPoetCoreDataKit
.
You can add this project as a package dependency in your Package.swift
file:
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:
targets: [
.target(
name: "YourLibrary",
dependencies: [
.product(name: "CoreDataKit", package: "CypherPoetCoreDataKit"),
],
...
),
...
]
Then simply import CoreDataKit
wherever you’d like to use it.
Currently, usage of these utilities is best demonstrated by the various example applications here. 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.
- Xcode 13.0+ (Recommended)
Documentation is generated by Swift Doc. Installation instructions can be found here, 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 exists to automatically generate docs at the root level and serve them on the project's gh-pages
branch.
CypherPoetCoreDataKit
is available under the MIT license. See the LICENSE file for more info.