PyObjC-framework-CoreData provides Python wrappers for Apple's Core Data framework on macOS. Core Data is a powerful framework that offers generalized and automated solutions for object life-cycle management, object graph persistence, and change tracking. This package, currently at version 12.1, is part of the broader PyObjC project, which typically sees minor releases every few months and major version updates roughly annually to align with macOS SDK changes.
pip install pyobjc-framework-coredataVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to programmatically define a Core Data model, set up an `NSPersistentContainer` with an in-memory store, create, save, and fetch `NSManagedObject` instances using PyObjC. It highlights the use of `NSPersistentContainer` for simplified stack management and the Python-Objective-C bridge mechanics, particularly for asynchronous operations like loading persistent stores.
Ensure your project uses a Python version compatible with the installed PyObjC version (currently Python 3.10+ for v12.1). Refer to PyPI metadata for exact requirements.
Review Apple's Core Data documentation for equivalent or alternative API usage. If applicable, migrate to newer Core Data APIs or adjust logic to avoid the removed constant.
Code that directly interacts with Objective-C `init` methods at a low level, or relies on specific reference counting behavior before v11.1, may need review. Most high-level usage should be unaffected, but advanced use cases may require adjustment.
If subclassing `NSManagedObject` in Python, be mindful of `__new__` and `__init__` interactions. For PyObjC-provided `__new__`, avoid overriding `__init__`. For user-implemented `__new__`, ensure `__init__` is correctly called, passing `self` and any arguments as needed.
When developing multi-threaded applications with PyObjC and Core Data, strictly adhere to Core Data's concurrency guidelines: use a dedicated `NSManagedObjectContext` per thread, typically a main context for UI and private queue contexts for background operations, always using `performBlock` or `performBlockAndWait`.
Always call `context.save()` after creating, modifying, or deleting `NSManagedObject` instances to persist changes to the underlying store.