Skip to content

Releases: spnkr/ActiveCoreData

0.7.2

16 Aug 01:58
Compare
Choose a tag to compare
  • visionOS compatibility

0.7.1

02 Aug 01:23
Compare
Choose a tag to compare

Xcode 15 support: Removing Predicate typealias to NSPredicate

Full Changelog: 0.7.0...0.7.1

0.7.0

08 Jul 01:46
Compare
Choose a tag to compare

What's Changed

  • Renaming package from CoreDataPlus to ActiveCoreData by @spnkr in #10

Full Changelog: 0.6.2...0.7.0

0.6.2

24 May 03:41
1682310
Compare
Choose a tag to compare

What's Changed

  • Adding a way to safely back up your database to disk - by @spnkr in #9

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

28 Feb 18:50
3f4cd8e
Compare
Choose a tag to compare

What's Changed

  1. ManagedObjectFindOrCreateBy has been split into ManagedObjectFindOrCreateBy and ManagedObjectFind.
  2. Updated documentation and repo structure

Full Changelog: 0.6.0...0.6.1

0.6.0

22 Feb 21:00
20cea52
Compare
Choose a tag to compare

What's Changed

  • Automatic creation and management of the Core Data stack by @spnkr in #7

Overview

Adds optional automatic creation and management of NSManagedObjectContexts 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

  1. Adds CoreDataPlusStore
  2. Adds CoreDataContainer protocol
  3. New CoreDataPlus.setup(...) methods
  4. Makes CoreDataPlus.setup(...) throwable
  5. Updated example app to work without an AppDelegate

Notes

Add CoreDataPlusStore

  • CoreDataPlusStore automatically sets up NSManagedObjectContext'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, implement CoreDataContainer 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

25 Jan 22:04
da1886c
Compare
Choose a tag to compare

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

18 Jan 02:04
c312150
Compare
Choose a tag to compare

What's Changed

  • Unit tests
  • Added optional automatic context management
  • Simplified destroyAll() method

Full Changelog: 0.4.5...0.5.0

0.4.5

04 Jan 00:58
Compare
Choose a tag to compare

Adding optional limit parameter to searchFor

let results = Drawing.searchFor(Predicate("foo = %@", "bar"), limit: 1, context: viewContext)

0.4.4

30 Dec 01:30
Compare
Choose a tag to compare

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:

  1. The @FetchRequest property wrapper.
    • Using a nil predicate can cause unexpected behavior if you dynamically assign or edit the predicate at runtime.
  2. 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