CoreDatabase is a powerful, type-safe Swift framework for CoreData and CloudKit integration, designed to simplify database operations with modern Swift features.
- Async/Await Support: Seamless asynchronous database operations
- Type-Safe Object Identifiers: Robust
ObjectIdwrapper - CloudKit Sharing: Built-in support for cross-device synchronization
- Comprehensive Logging: Advanced error tracking and reporting
- Flexible Store Configurations: Local, cloud, and hybrid storage options
- Combine-Based Change Tracking: Reactive database observation
- Automatic Merging: Intelligent change management across contexts
- iOS 15.0+
- macOS 12.0+
- Swift 5.5+
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/NSFuntik/SwiftToolkit.git", from: "1.0.0")
]// Standard local database
let database = Database()
// With custom store configuration
let database = Database(
storeDescriptions: [.localData()],
modelBundle: .module
)
// CloudKit-enabled database
let database = Database(
storeDescriptions: [.cloudWithShare()],
modelBundle: .module
)// Edit operation
try await database.edit { ctx in
let user = User(context: ctx)
user.name = "John Doe"
}
// Fetch operation
let users = try await database.fetch { ctx in
User.all(ctx)
}// Create a share
let share = try await database.makeShare(user)
// Accept a share
try await database.accept(shareMetadata)// Observe changes to a specific entity
User.didChange(database)
.sink { change in
print("Inserted: \(change.inserted)")
print("Updated: \(change.updated)")
print("Deleted: \(change.deleted)")
}class CustomLogger: DatabaseLogger {
func logError(_ error: Error, context: [String: Any]?) {
// Custom error handling
}
}let storeDescriptions = [
NSPersistentStoreDescription.localData(),
NSPersistentStoreDescription.cloudWithShare()
]
let database = Database(storeDescriptions: storeDescriptions)CoreDatabase provides comprehensive error handling through the DatabaseLogger protocol and DatabaseError enum.
- Automatic context management
- Efficient background processing
- Intelligent change tracking
- Requires iOS 15.0+ due to async/await and modern CoreData features
- CloudKit sharing requires Apple ecosystem