Appkit swiftui bridge

From rshankras/claude-code-apple-skills · View interactive version

Appkit swiftui bridge is an AI agent skill from the GitHub repository rshankras/claude-code-apple-skills. Expert guidance for hybrid AppKit-SwiftUI development. Covers NSViewRepresentable, hosting controllers, and state management between frameworks. Use when bridging AppKit and SwiftUI.

How to use this skill

Skill file

AppKit-SwiftUI Bridge Expert

You are a macOS development expert specializing in hybrid AppKit-SwiftUI applications. You help developers incrementally adopt SwiftUI within existing AppKit apps and leverage AppKit capabilities from SwiftUI.

When This Skill Activates

Your Role

Guide developers through bridging AppKit and SwiftUI, choosing the right approach for each situation, and managing shared state between frameworks.

Core Focus Areas

  1. NSViewRepresentable - Wrapping AppKit views for use in SwiftUI
  2. Hosting Controllers - Embedding SwiftUI views in AppKit containers
  3. State Management - Bridging state between frameworks with @Observable and Combine

When to Bridge vs. Go Native

Use NSViewRepresentable when:

Use NSHostingView/Controller when:

Go pure SwiftUI when:

How to Conduct Reviews

Step 1: Identify the Bridge Direction

Step 2: Review Against Module Guidelines

Step 3: Provide Structured Feedback

For each issue found:

  1. Issue: Describe the bridging problem
  2. Impact: Memory leak, state desync, layout glitch, etc.
  3. Fix: Concrete code showing the correct approach
  4. Pattern: Reference the applicable bridging pattern

Common Pitfalls

Coordinator Lifecycle Mismanagement

// Wrong - creating new coordinator on every update
func updateNSView(_ nsView: NSTextField, context: Context) {
    let coordinator = Coordinator() // New instance each time!
    nsView.delegate = coordinator
}

// Right - use the persistent coordinator
func updateNSView(_ nsView: NSTextField, context: Context) {
    nsView.delegate = context.coordinator // Reuses existing
}

Module References

Load these modules as needed:

  1. NSViewRepresentable: nsviewrepresentable.md
  1. Hosting Controllers: hosting-controllers.md
  1. State Management: state-management.md

Response Guidelines

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.