# SwiftUI and AppKit Bridge

Bridges SwiftUI to AppKit narrowly for representables, windows, menus and responders.

- Repository: https://github.com/robinebers/openusage (4503 stars)
- Category: Engineering
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add robinebers/openusage --skill macos-appkit-interop -g -a claude-code -y`
Codex: `npx skills add robinebers/openusage --skill macos-appkit-interop -g -a codex -y`
Cursor: `npx skills add robinebers/openusage --skill macos-appkit-interop -g -a cursor -y`
Gemini CLI: `npx skills add robinebers/openusage --skill macos-appkit-interop -g -a gemini-cli -y`

## Description

Bridge macOS SwiftUI into AppKit narrowly. Use when implementing representables, reaching NSWindow or panels, handling menus, or using the responder chain.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# AppKit Interop

## Quick Start

Use this skill when SwiftUI is close but not quite enough for native macOS behavior.
Keep the bridge as small and explicit as possible. SwiftUI should usually remain
the source of truth, while AppKit handles the imperative edge.

## Choose The Smallest Bridge

- Use pure SwiftUI when the required behavior already exists in scenes, toolbars, commands, inspectors, or standard controls.
- Use `NSViewRepresentable` when you need a specific AppKit view with lightweight lifecycle needs.
- Use `NSViewControllerRepresentable` when you need controller lifecycle, delegation, or presentation coordination.
- Use direct AppKit window or app hooks when you need `NSWindow`, responder-chain, menu validation, panels, or app-level behavior.

## Workflow

1. Name the capability gap precisely.
   - Window behavior
   - Text system behavior
   - Menu validation
   - Drag and drop
   - File open/save panels
   - First responder control

2. Pick the smallest boundary that solves it.
   - Avoid porting a whole screen to AppKit when one wrapped control or coordinator would do.

3. Keep ownership explicit.
   - SwiftUI owns value state, selection, and observable models.
   - AppKit objects stay inside the representable, coordinator, or bridge object.

4. Expose a narrow interface back to SwiftUI.
   - Bindings for editable state
   - Small callbacks for events
   - Focused bridge services only when necessary

5. Validate lifecycle assumptions.
   - SwiftUI may recreate representables.
   - Coordinators exist to hold delegate and target-action glue, not as a second app architecture.

## References

The rest: https://github.com/robinebers/openusage/blob/HEAD/.agents/skills/macos-appkit-interop/SKILL.md
