appkit-swiftui-bridge

Guides hybrid AppKit-SwiftUI development using NSViewRepresentable, hosting controllers, and shared state patterns.

70|4|Updated Jul 22, 2025
One-click install
npx skills add https://github.com/AlexW00/Zettel --skill appkit-swiftui-bridge-alexw00
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: appkit-swiftui-bridge
Source: https://github.com/AlexW00/Zettel/tree/main/.agents/skills/macos-development/appkit-swiftui-bridge
Command: npx skills add https://github.com/AlexW00/Zettel --skill appkit-swiftui-bridge-alexw00

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Bridging AppKit and SwiftUI in a single macOS app is error-prone: coordinator lifecycle bugs, retain cycles, stale state, and layout glitches are common when wrapping views in either direction. This Skill provides expert review and implementation guidance for hybrid AppKit-SwiftUI code so both frameworks stay synchronized and memory-safe. ## Core Features & Use Cases - NSViewRepresentable Guidance: Wrap AppKit views like NSTextView and NSTableView for use inside SwiftUI, with correct coordinator, sizeThatFits, and dismantling patterns. - Hosting Controller Patterns: Embed SwiftUI views in AppKit via NSHostingView and NSHostingController, including windows, split views, sheets, and incremental adoption phases. - Cross-Framework State Management: Bridge state with @Observable, Combine, NotificationCenter, UserDefaults, and the responder chain while avoiding retain cycles and threading bugs. - Use Case: You are modernizing a legacy AppKit note-taking app and want to add a SwiftUI settings panel and sidebar without rewriting the whole app. This Skill reviews your bridging code, flags coordinator leaks, and shows the correct hosting pattern for your macOS deployment target. ## Quick Start Ask the assistant to review your NSViewRepresentable implementation or to show how to embed a SwiftUI view inside your existing AppKit window.

Frequently Asked Questions about appkit-swiftui-bridge

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I wrap an AppKit view for use in SwiftUI?▼

Implement NSViewRepresentable with makeNSView to create the AppKit view, updateNSView to sync SwiftUI state, and makeCoordinator for delegate callbacks. Use sizeThatFits on macOS 13+ to control layout and dismantleNSView to clean up observers.

How do I embed a SwiftUI view in an existing AppKit app?▼

Use NSHostingView to place SwiftUI inside an existing NSView hierarchy, or NSHostingController when you need a full view controller for sheets, split views, or windows. Set sizingOptions explicitly and update rootView when data changes.

When should I use NSViewRepresentable instead of pure SwiftUI?▼

Use NSViewRepresentable when SwiftUI lacks a native equivalent, such as NSTextView rich text editing, or when performance requires AppKit, like NSTableView with over 100k rows. Go pure SwiftUI when full API coverage exists on macOS 14+.

How do I share state between AppKit and SwiftUI?▼

On macOS 14+, share an @Observable class and use withObservationTracking on the AppKit side. For older targets, use a Combine ObservableObject with @Published properties and sink subscriptions, always dispatching UI updates to the main thread.

Why does my NSViewRepresentable coordinator cause a retain cycle?▼

Retain cycles happen when Combine sinks or callbacks capture self strongly, or when the coordinator's parent reference is never refreshed. Use [weak self] in closures, update coordinator.parent in updateNSView, and invalidate observers in dismantleNSView.