CoreStore
Unleashing the real power of Core Data with the elegance and safety of Swift
Install / Use
/learn @JohnEstropia/CoreStoreREADME
- Swift 5.9: iOS 16.0+ / macOS 13.0+ / watchOS 9.0+ / tvOS 16.0+
- Previously supported Swift versions: Swift 5.4, Swift 5.3, Swift 5.7
Upgrading from previous CoreStore versions? Check out the 🆕 features and make sure to read the Change logs.
CoreStore is part of the Swift Source Compatibility projects.
Contents
- TL;DR (a.k.a. sample codes)
- Why use CoreStore?
- Architecture
- CoreStore Tutorials (All of these have demos in the Demo app project!)
- Roadmap
- Installation
- Changesets
- Contact
- Who uses CoreStore?
- License
TL;DR (a.k.a. sample codes)
Pure-Swift models:
class Person: CoreStoreObject {
@Field.Stored("name")
var name: String = ""
@Field.Relationship("pets", inverse: \Dog.$master)
var pets: Set<Dog>
}
(Classic NSManagedObjects also supported)
Setting-up with progressive migration support:
dataStack = DataStack(
xcodeModelName: "MyStore",
migrationChain: ["MyStore", "MyStoreV2", "MyStoreV3"]
)
Adding a store:
dataStack.addStorage(
SQLiteStore(fileName: "MyStore.sqlite"),
completion: { (result) -> Void in
// ...
}
)
Starting transactions:
dataStack.perform(
asynchronous: { (transaction) -> Void in
let person = transaction.create(Into<Person>())
person.name = "John Smith"
person.age = 42
},
completion: { (result) -> Void in
switch result {
case .success: print("success!")
case .failure(let error): print(error)
}
}
)
Fetching objects (simple):
let people = try dataStack.fetchAll(From<Person>())
Fetching objects (complex):
let people = try dataStack.fetchAll(
From<Person>()
.where(\.age > 30),
.orderBy(.ascending(\.name), .descending(.\age)),
.tweak({ $0.includesPendingChanges = false })
)
Querying values:
let maxAge = try dataStack.queryValue(
From<Person>()
.select(Int.self, .maximum(\.age))
)
But really, there's a reason I wrote this huge README. Read up on the details!
Check out the Demo app project for sample codes as well!
Why use CoreStore?
CoreStore was (and is) heavily shaped by real-world needs of developing data-dependent apps. It enforces safe and convenient Core Data usage while letting you take advantage of the industry's encouraged best practices.
Features
- 🆕SwiftUI and Combine API utilities.
ListPublishers andObjectPublishers now have their@ListStateand@ObjectStateSwiftUI property wrappers. CombinePublishers are also available through theListPublisher.reactive,ObjectPublisher.reactive, andDataStack.reactivenamespaces. - Backwards-portable DiffableDataSources implementation!
UITableViewsandUICollectionViewsnow have a new ally:ListPublishers provide diffable snapshots that make reloading animations very easy and very safe. Say goodbye toUITableViewsandUICollectionViewsreload errors! - 💎Tight design around Swift’s code elegance and type safety. CoreStore fully utilizes Swift's community-driven language features.
- 🚦Safer concurrency architecture. CoreStore makes it hard to fall into common concurrency mistakes. The main
NSManagedObjectContextis strictly read-only, while all updates are done through serial transactions. (See Saving and processing transactions) - 🔍Clean fetching and querying API. Fetching objects is easy, but querying for raw aggregates (
min,max, etc.) and raw property values is now just as convenient. (See Fetching and querying) - 🔭Type-safe, easy to configure observers. You don't have to deal with the burden of setting up
NSFetchedResultsControllers and KVO. As an added bonus, list and object observable types all support multiple observers. This means you can have multiple view controllers efficiently share a single resource! (See Observing changes and notifications) - 📥Efficient importing utilities. Map your entities once with their corresponding import source (JSON for example), and importing from transactions becomes elegant. Uniquing is also done with an efficient find-and-replace algorithm. *(Se
Related Skills
node-connect
342.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
342.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.7kCommit, push, and open a PR
