Agent Skills › robinebers/openusage › macos-appkit-interop

macos-appkit-interop

GitHub

指导在 macOS 开发中,当 SwiftUI 无法满足原生需求时,如何以最小化桥接方式与 AppKit 交互。涵盖 Representables、窗口面板、菜单及响应者链的使用规范,强调保持数据源单一和生命周期安全。

.agents/skills/macos-appkit-interop/SKILL.md robinebers/openusage

触发场景

实现 SwiftUI 与 AppKit 的互操作 处理 NSWindow、菜单或拖拽等原生功能 需要访问第一响应者链

安装

npx skills add robinebers/openusage --skill macos-appkit-interop -g -y
更多选项

非标准路径

npx skills add https://github.com/robinebers/openusage/tree/main/.agents/skills/macos-appkit-interop -g -y

不安装直接使用

npx skills use robinebers/openusage@macos-appkit-interop

指定 Agent (Claude Code)

npx skills add robinebers/openusage --skill macos-appkit-interop -a claude-code -g -y

安装 repo 全部 skill

npx skills add robinebers/openusage --all -g -y

预览 repo 内 skill

npx skills add robinebers/openusage --list

SKILL.md

Frontmatter
{
    "name": "macos-appkit-interop",
    "description": "Bridge macOS SwiftUI into AppKit narrowly. Use when implementing representables, reaching NSWindow or panels, handling menus, or using the responder chain."
}

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

  • references/representables.md: choosing between view and view-controller wrappers, plus coordinator patterns.
  • references/window-panels.md: window access, utility windows, and open/save panels.
  • references/responder-menus.md: first responder, command routing, and menu validation.
  • references/drag-drop-pasteboard.md: pasteboard, file URLs, and desktop drag/drop edges.

Guardrails

  • Do not duplicate the source of truth between SwiftUI and AppKit.
  • Do not let Coordinator become an unstructured dumping ground.
  • Do not store long-lived NSView or NSWindow instances globally without a strong ownership reason.
  • Prefer a tiny tested bridge over rewriting the feature in raw AppKit.
  • If a pattern can remain entirely in macos-swiftui-patterns, keep it there.

Output Expectations

Provide:

  • the exact SwiftUI limitation being crossed
  • the smallest recommended bridge type
  • the data-flow boundary between SwiftUI and AppKit
  • the lifecycle or validation risks to watch

版本历史

  • 70acd4f 当前 2026-08-20 09:01

同 Skill 集合

.agents/skills/appkit-interop/SKILL.md
.agents/skills/build-and-run-macos-app/SKILL.md
.agents/skills/build-run-debug/SKILL.md
.agents/skills/fix-codesign-error/SKILL.md
.agents/skills/liquid-glass/SKILL.md
.agents/skills/macos-build-run-debug/SKILL.md
.agents/skills/macos-liquid-glass/SKILL.md
.agents/skills/macos-packaging-notarization/SKILL.md
.agents/skills/macos-signing-entitlements/SKILL.md
.agents/skills/macos-swiftpm/SKILL.md
.agents/skills/macos-swiftui-patterns/SKILL.md
.agents/skills/macos-telemetry/SKILL.md
.agents/skills/macos-test-triage/SKILL.md
.agents/skills/macos-view-refactor/SKILL.md
.agents/skills/macos-window-management/SKILL.md
.agents/skills/packaging-notarization/SKILL.md
.agents/skills/pricing-update/SKILL.md
.agents/skills/signing-entitlements/SKILL.md
.agents/skills/sol-loop/SKILL.md
.agents/skills/swiftpm-macos/SKILL.md
.agents/skills/swiftui-patterns/SKILL.md
.agents/skills/telemetry/SKILL.md
.agents/skills/test-macos-app/SKILL.md
.agents/skills/test-triage/SKILL.md
.agents/skills/view-refactor/SKILL.md
.agents/skills/window-management/SKILL.md

元信息

文件数
0
版本
1acc905
Hash
64b0797b
收录时间
2026-08-20 09:01

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.156.0. UTC+08:00, 2026-11-06 02:14
浙ICP备14020137号-1