appkit-swiftui-bridge

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

Updated Mar 12, 2026
One-click install
npx skills add https://github.com/RavitejaKarra24/dotfiles --skill appkit-swiftui-bridge-ravitejakarra24
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: appkit-swiftui-bridge
Source: https://github.com/RavitejaKarra24/dotfiles/tree/main/agents/.agents/skills/macos-development/appkit-swiftui-bridge
Command: npx skills add https://github.com/RavitejaKarra24/dotfiles --skill appkit-swiftui-bridge-ravitejakarra24

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Bridging AppKit and SwiftUI in a single macOS app is error-prone: coordinators leak memory, state desynchronizes between frameworks, and layout breaks when frames are set manually. This Skill provides expert guidance and reviewed code patterns for wrapping AppKit views in SwiftUI, hosting SwiftUI inside AppKit apps, and keeping state synchronized across both frameworks. ## Core Features & Use Cases - NSViewRepresentable Patterns: Wrap AppKit views like NSTextView and NSTableView for SwiftUI, with correct coordinator lifecycle, dismantleNSView cleanup, and sizeThatFits layout integration. - Hosting Controllers: Embed SwiftUI in AppKit via NSHostingView and NSHostingController, including sheets, split views, windows, and a four-phase incremental adoption strategy. - State Management: Bridge state with @Observable (macOS 14+), Combine, NotificationCenter, UserDefaults, or the responder chain, with guidance on choosing the right approach. - Use Case: You are modernizing a legacy AppKit app and need to embed a new SwiftUI settings panel while keeping the existing NSTableView-based main window. The Skill walks you through NSHostingController setup, shared @Observable state, and common retain-cycle pitfalls. ## Quick Start Ask the assistant to help you wrap an AppKit view in SwiftUI or embed a SwiftUI view in your existing AppKit app, and it will apply the bridging patterns from this Skill.

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 dismantleNSView to remove observers and prevent leaks.

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

Use NSHostingView to embed SwiftUI inside an NSView hierarchy, or NSHostingController when you need a full view controller for sheets, split views, or windows. Set sizingOptions explicitly to control layout behavior.

NSViewRepresentable vs NSHostingController: which should I use?

Use NSViewRepresentable when SwiftUI lacks a native equivalent or you need AppKit performance, such as NSTableView with 100k+ rows. Use NSHostingController when incrementally adopting SwiftUI inside an AppKit app shell.

How do I share state between AppKit and SwiftUI?

On macOS 14+, use an @Observable class shared by both sides; SwiftUI updates automatically and AppKit observes via withObservationTracking. For older targets, use a Combine ObservableObject with @Published properties and sink subscriptions.

Why does my NSViewRepresentable leak memory or stop updating?

Leaks usually come from leaving dismantleNSView empty, so KVO observations and NotificationCenter observers are never removed. Stale updates happen when the coordinator's parent reference is not refreshed in updateNSView.

When should I avoid bridging and use pure SwiftUI instead?

Go pure SwiftUI when starting a new project targeting macOS 14+, when the feature has full SwiftUI API coverage, and when no AppKit-specific behavior is required. Bridging adds lifecycle and memory-management complexity.