{"id":6131,"library":"pyobjc-framework-mapkit","title":"PyObjC MapKit Framework","description":"pyobjc-framework-mapkit provides Python bindings for Apple's MapKit framework on macOS, enabling Python applications to integrate maps, display points of interest, and manage map data. It is part of the larger PyObjC project, currently at version 12.1, and follows a release cadence tied to macOS SDK updates and Python compatibility.","status":"active","version":"12.1","language":"en","source_language":"en","source_url":"https://github.com/ronaldoussoren/pyobjc","tags":["macos","framework","mapkit","pyobjc","gui"],"install":[{"cmd":"pip install pyobjc-framework-mapkit","lang":"bash","label":"Install specific framework"},{"cmd":"pip install pyobjc","lang":"bash","label":"Install all PyObjC frameworks (including MapKit)"}],"dependencies":[{"reason":"Provides the core bridge between Python and Objective-C, essential for all PyObjC framework bindings.","package":"pyobjc-core","optional":false}],"imports":[{"symbol":"MKMapView","correct":"from MapKit import MKMapView"},{"symbol":"CLLocationCoordinate2D","correct":"from MapKit import CLLocationCoordinate2D"},{"note":"Commonly needed for GUI applications using AppKit alongside MapKit.","symbol":"NSApplication","correct":"from AppKit import NSApplication"}],"quickstart":{"code":"import objc\nfrom AppKit import NSApplication, NSWindow, NSView, NSMakeRect, NSApp\nfrom Foundation import NSObject\nfrom MapKit import MKMapView, CLLocationCoordinate2D, MKCoordinateSpan, MKCoordinateRegion\n\nclass AppDelegate(NSObject):\n    def applicationDidFinishLaunching_(self, notification):\n        print(\"PyObjC MapKit Application Launched!\")\n        # Create a window\n        self.window = NSWindow.alloc().initWithContentRect_styleMask_backing_defer_(\n            NSMakeRect(100, 100, 800, 600),\n            (NSWindow.NSTitledWindowMask | NSWindow.NSClosableWindowMask | NSWindow.NSResizableWindowMask),\n            NSWindow.NSBackingStoreBuffered,\n            False\n        )\n        self.window.setTitle_(\"PyObjC MapKit Example\")\n        \n        # Create an MKMapView\n        self.mapView = MKMapView.alloc().initWithFrame_(self.window.contentView().frame())\n        self.mapView.setAutoresizingMask_(NSView.NSViewWidthSizable | NSView.NSViewHeightSizable)\n        \n        # Define a location (e.g., San Francisco)\n        coordinate = CLLocationCoordinate2D(latitude=37.7749, longitude=-122.4194)\n        span = MKCoordinateSpan(latitudeDelta=0.1, longitudeDelta=0.1)\n        region = MKCoordinateRegion(center=coordinate, span=span)\n        \n        self.mapView.setRegion_(region)\n        \n        # Add the map view to the window\n        self.window.contentView().addSubview_(self.mapView)\n        \n        self.window.makeKeyAndOrderFront_(None)\n\n    def applicationShouldTerminateAfterLastWindowClosed_(self, sender):\n        return True\n\n# Initialize and run the application\napp = NSApplication.sharedApplication()\ndelegate = AppDelegate.alloc().init()\napp.setDelegate_(delegate)\nNSApp.run()","lang":"python","description":"This quickstart demonstrates how to create a basic macOS application window using AppKit, then embed and display an MKMapView from the MapKit framework, centering it on a specific geographical coordinate. It requires running on macOS with a functional PyObjC installation."},"warnings":[{"fix":"Upgrade to a supported Python version (3.10 or later for PyObjC 12.x) or pin an older PyObjC version compatible with your Python environment.","message":"PyObjC frequently drops support for older Python versions. PyObjC 12.0 dropped support for Python 3.9, and PyObjC 11.0 dropped support for Python 3.8. Always check the release notes for minimum Python requirements.","severity":"breaking","affected_versions":"11.0, 12.0"},{"fix":"Review custom Python `__new__` and `__init__` methods on Objective-C subclasses to ensure correct reference handling, especially when dealing with `alloc()` and `init*()` patterns. Refer to PyObjC's documentation on memory management.","message":"PyObjC 11.1 aligned its Automatic Reference Counting (ARC) semantics for Objective-C 'init' methods with `clang` documentation. This means 'init' methods now correctly steal a reference to `self` and return a new reference, which can affect memory management and object lifecycle if custom `__new__` or `__init__` methods are used without careful consideration.","severity":"breaking","affected_versions":">=11.1"},{"fix":"If implementing custom object creation, use `__new__` for Objective-C object setup and ensure `__init__` is only used when a custom `__new__` is explicitly defined. Avoid relying on `__init__` directly on PyObjC-bridged classes without a custom `__new__`.","message":"PyObjC 10.3 introduced changes to how `__init__` interacts with `__new__`. While `__init__` was initially disallowed for classes using PyObjC's `__new__`, version 10.3.1 reintroduced support for `__init__` when a user-defined `__new__` is present. However, code relying on the PyObjC-provided `__new__` still cannot use `__init__`.","severity":"gotcha","affected_versions":"10.3, 10.3.1"},{"fix":"Avoid using Python's experimental free-threading features with PyObjC until explicit full support is announced. Continue to use PyObjC in single-threaded contexts or with traditional Python threading models.","message":"PyObjC introduced experimental support for Python 3.13's free-threading (PEP 703) in version 11.0. However, subsequent release notes (e.g., for v10.3, mentioning 3.13 support) clarified that PyObjC does *not* fully support free threading at this time. Attempting to use free-threading features with PyObjC may lead to undefined behavior or crashes.","severity":"gotcha","affected_versions":">=11.0 (with Python 3.13+)"},{"fix":"If migrating to a newer PyObjC version or macOS, review your application for usage of frameworks that may have been deprecated or removed by Apple. Update to modern alternatives where necessary. This is a common pattern across all `pyobjc-framework-*` packages.","message":"PyObjC frameworks are closely tied to macOS SDKs. Older or deprecated frameworks may be removed from PyObjC bindings as they are removed from macOS itself. For instance, `IMServicePlugIn` bindings were removed in PyObjC 10.0 because the framework was deprecated in macOS 10.13 and removed in macOS 14.","severity":"breaking","affected_versions":">=10.0"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}