Releases: spnkr/ActiveCoreData
0.7.2
0.7.1
Xcode 15 support: Removing Predicate
typealias to NSPredicate
Full Changelog: 0.7.0...0.7.1
0.7.0
0.6.2
What's Changed
Back up your database to a .sqlite file. Safely copies the specified NSPersistentStore
to a temporary file, so this works even if your database is in use.
CoreDataPlusStore.shared.backupToFile(fileName: "my-file-name", completion: { url in
print(url)
})
Full Changelog: 0.6.1...0.6.2
0.6.1
0.6.0
What's Changed
Overview
Adds optional automatic creation and management of NSManagedObjectContext
s so you don't have to create your own data access class or layer.
If you already have a data access layer, you can use that instead by implementing the new CoreDataContainer
protocol.
Changes
- Adds
CoreDataPlusStore
- Adds
CoreDataContainer
protocol - New
CoreDataPlus.setup(...)
methods - Makes
CoreDataPlus.setup(...)
throwable - Updated example app to work without an AppDelegate
Notes
Add CoreDataPlusStore
CoreDataPlusStore
automatically sets upNSManagedObjectContext
's for your app.- It's a singleton, accessible via
CoreDataPlusStore.shared
- See Example App for UIKit and SwiftUI examples
- To use your own class for managing
NSManagedObjectContext
's, implementCoreDataContainer
in your class
How to use CoreDataPlusStore
with SwiftUI:
@main
struct BestAppEver: App {
let yourDataStore = CoreDataPlusStore.shared
@Environment(\.scenePhase) private var phase
init() {
do {
try CoreDataPlus.setup(store: CoreDataPlusStore.shared)
} catch {
NSLog(error.localizedDescription)
}
}
var body: some Scene {
WindowGroup {
ContentView()
.environment(\.managedObjectContext, yourDataStore.viewContext)
}
// save core data when the app goes into the background
.onChange(of: phase) { newPhase in
switch newPhase {
case .background:
try! yourDataStore.viewContext.save()
default:
break
}
}
}
}
Add CoreDataContainer
protocol
Use your own data access layer by implementing CoreDataContainer
in that class.
public protocol CoreDataContainer {
var viewContext: NSManagedObjectContext { get }
var backgroundContext: NSManagedObjectContext { get }
}
Full Changelog: 0.5.1...0.6.0
0.5.1
What's Changed
- Added ability to delete only some items:
Country.destroyAll(matching: withSpanishLanguage)
destroyAll(...)
no longer automatically saves the context- Tests for destroyAll and
countFor(...)
Details on destroyAll(...)
:
Removes all objects from Core Data.
Deletes them from the context.
Drawing.destroyAll(context: viewContext)
You can also specify a predicate to only delete some items:
let withSpanishLanguage = Predicate("languages contains %@", es)
Country.destroyAll(matching: withSpanishLanguage)
Remember to save the context after deleting objects.
Full Changelog: 0.5.0...0.5.1
0.5.0
What's Changed
- Unit tests
- Added optional automatic context management
- Simplified destroyAll() method
Full Changelog: 0.4.5...0.5.0
0.4.5
0.4.4
Added Predicate.empty()
method.
Returns a new, non-nil, NSPredicate object that will match every single row in the database.
This is especially helpful with:
- The @FetchRequest property wrapper.
- Using a nil predicate can cause unexpected behavior if you dynamically assign or edit the predicate at runtime.
- Other Core Data quirks around nil predicates and updating when you do fancy stuff.
Before:
@FetchRequest(sortDescriptors: [], predicate: nil)
After
@FetchRequest(sortDescriptors: [], predicate: Predicate.empty())
Full Changelog: 0.4.3...0.4.4