Python Bindings for SharedWithYouCore Framework
PyObjC is a bridge between Python and Objective-C, enabling Python scripts to use and extend Objective-C class libraries on macOS. The `pyobjc-framework-sharedwithyoucore` package provides Python wrappers for Apple's SharedWithYouCore framework, which allows applications to collaborate and share documents directly with Messages, Mail, and FaceTime apps. It is actively maintained, with new releases typically aligning with macOS SDK updates and Python version support. [3, 22]
Warnings
- breaking Python 3.9 support was dropped in PyObjC 12.0. Version 12.0 incorrectly listed Python 3.9 in its packaging metadata, causing installation failures when building from source. This was corrected in version 12.1. [2, 17]
- breaking PyObjC 11.0 dropped support for Python 3.8. [2]
- gotcha PyObjC 10.3 introduced a change that broke `__init__` when `__new__` was *not* explicitly implemented in Python classes. Version 10.3.1 partially reverted this, allowing `__init__` when `__new__` is user-implemented. However, classes relying on PyObjC's default `__new__` still cannot use `__init__` in the same way. [2, 27]
- gotcha While PyObjC supports free-threading (experimental in Python 3.13), Apple's Cocoa frameworks are generally not thread-safe. Many GUI elements and certain Core Foundation types require interaction on the main thread. Always manage `NSAutoreleasePool`s explicitly in new threads. [1, 11]
- breaking PyObjC 11.1 aligned its core bridge behavior for Automatic Reference Counting (ARC) with `clang`'s documentation, specifically for initializer methods (e.g., `init` family). This means methods in the 'init' family now correctly steal a reference to `self` and return a new reference, changing the proxy behavior for `[NSObject alloc]`. [2]
Install
-
pip install pyobjc-framework-sharedwithyoucore
Imports
- SWCollaborationCoordinator
from SharedWithYouCore import SWCollaborationCoordinator
- SWStartCollaborationAction
from SharedWithYouCore import SWStartCollaborationAction
Quickstart
from Foundation import NSAutoreleasePool
from SharedWithYouCore import SWCollaborationCoordinator
import objc
# PyObjC requires an NSAutoreleasePool for many Cocoa operations
pool = NSAutoreleasePool.alloc().init()
try:
# Get the SWCollaborationCoordinator class
CoordinatorClass = SWCollaborationCoordinator
# Instantiate the coordinator
coordinator = CoordinatorClass.alloc().init()
print(f"Successfully instantiated SWCollaborationCoordinator: {coordinator}")
print(f"Is it an Objective-C object? {isinstance(coordinator, objc.objc_object)}")
except Exception as e:
print(f"An error occurred: {e}")
finally:
# Release the autorelease pool to clean up Cocoa objects
del pool