Introduce persistence framework abstraction layer - #271
Open
danielbarela wants to merge 1 commit into
Open
Conversation
This sets up the persistence framework. Still uses Magical Record to promote an incremental update.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduce persistence framework abstraction layer
Summary
This change introduces the initial persistence framework required to migrate MAGE away from direct Magical Record usage while preserving existing Core Data behavior.
A new
PersistenceSwift package defines a persistence abstraction layer, including aPersistenceProtocol, shared persistence container, Core Data convenience extensions, and Objective-C bridging APIs. The initial implementation continues to use Magical Record internally throughMagicalRecordPersistence, allowing migration to happen incrementally without requiring a full rewrite of existing persistence code.The application startup flow has been updated to initialize the new persistence container before launching the application, and existing Core Data usage has been routed through the new persistence APIs.
What Changed
New Persistence Swift Package
Added a new
Persistencepackage containing:PersistenceProtocolPersistenceContainerPersistenceResultCore Data utilities:
NSManagedObjectContextfetch helpersNSManagedObjectcreation and lookup helpersMagical Record Migration Adapter
Added
MagicalRecordPersistenceas the firstPersistenceProtocolimplementation.This adapter:
Objective-C Compatibility Layer
Added
ObjCCoreDataPersistenceto allow existing Objective-C code to interact with the new persistence abstraction.Updated existing startup canary writes to use:
ObjCCoreDataPersistence.writePersistenceResulthandlinginstead of directly calling Magical Record APIs.
Application Initialization Changes
Updated application startup:
MagicalRecord.setupMageCoreDataStack()callsMageInitializerProject Integration
Updated Xcode project configuration to:
Migration Strategy
This change intentionally keeps Magical Record as the backing implementation.
Future migrations can now happen incrementally:
PersistenceProtocolNSPersistentContainerimplementationTesting
Added initial Swift Testing target for the Persistence package.
Existing application behavior remains backed by Magical Record while exercising the new persistence entry points.
Follow-up Work
Potential follow-up work:
PersistenceContainerwith the existing dependency injection systemNSPersistentContainerimplementationReviewer Notes
A few areas worth reviewing:
PersistenceContainer.sharedis currently a singleton-style container. This is intentional for the migration phase but may eventually move into application dependency injection.MagicalRecordPersistencecurrently owns Magical Record initialization. This keeps migration incremental but couples the adapter to the current lifecycle.@unchecked Sendableis used around Core Data and Objective-C bridging. The thread-safety assumptions should remain documented as the abstraction evolves.