Automated summary
Provides expert guidance for bridging AppKit and SwiftUI in macOS apps, covering NSViewRepresentable, hosting controllers, and shared state management.
Strengths
- Clear decision criteria for choosing NSViewRepresentable, NSHostingView/Controller, or plain SwiftUI
- Concrete before/after code for classic pitfalls: coordinator lifecycle, missing dismantling, layout in the wrong phase
- Structured review workflow: identify the bridge direction, check the guidelines, then report issue / impact / fix
Limitations
- Covers only three areas (representables, hosting, state); nothing on menus, navigation, or drag-and-drop bridging
- Assumes prior SwiftUI and AppKit knowledge; it is not an introductory tutorial
- Read-only tooling (Read, Glob, Grep): it advises and reviews but cannot build or run the project
Use it whenever you need to embed an AppKit view in SwiftUI (or the reverse) or migrate an AppKit app to SwiftUI incrementally.
Not useful for a pure SwiftUI app with no AppKit content, or for non-macOS Apple platforms such as iOS.
Security analysis
SafeThe skill only uses read-only tools (Read, Glob, Grep) and contains purely advisory Swift/AppKit code examples. It does not instruct destructive actions, network calls, secret exfiltration, or execution of commands. The code snippets are illustrative and not executed by the agent.
No concerns found
How this analysis is madeExamples
I need rich text editing in a SwiftUI macOS view but TextEditor isn't enough. Show me how to wrap NSTextView with NSViewRepresentable, including the coordinator and proper dismantling.My AppKit app uses an NSSplitViewController and I want to replace the detail pane with a SwiftUI view. Which hosting approach should I use, and how do I pass and keep state in sync with it?Review my NSViewRepresentable wrapper around NSTableView — I suspect my coordinator is leaking and updates get slow with large data sets.name: appkit-swiftui-bridge description: Expert guidance for hybrid AppKit-SwiftUI development. Covers NSViewRepresentable, hosting controllers, and state management between frameworks. Use when bridging AppKit and SwiftUI. allowed-tools: [Read, Glob, Grep]
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
- User wants to bridge AppKit and SwiftUI
- User asks about
NSViewRepresentableorNSHostingView/NSHostingController - User wants to wrap an AppKit view for use in SwiftUI
- User wants to host SwiftUI inside an existing AppKit app
- User is migrating an AppKit app to SwiftUI incrementally
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
- NSViewRepresentable - Wrapping AppKit views for use in SwiftUI
- Hosting Controllers - Embedding SwiftUI views in AppKit containers
- State Management - Bridging state between frameworks with @Observable and Combine
When to Bridge vs. Go Native
Use NSViewRepresentable when:
- SwiftUI lacks a native equivalent (e.g.,
NSTextViewrich text,NSOpenGLView) - You need fine-grained control over AppKit view lifecycle
- Performance-critical views need AppKit optimization (e.g.,
NSTableViewwith 100k+ rows)
Use NSHostingView/Controller when:
- Incrementally adopting SwiftUI in an existing AppKit app
- A SwiftUI view is more concise for the job (e.g., complex layouts, animations)
- Building new features in SwiftUI within an AppKit shell
Go pure SwiftUI when:
- Starting a new project targeting macOS 14+
- The feature has full SwiftUI API coverage
- No AppKit-specific behavior is needed
How to Conduct Reviews
Step 1: Identify the Bridge Direction
- Is AppKit hosting SwiftUI, or SwiftUI wrapping AppKit?
- What's the minimum macOS deployment target?
- Are there performance or lifecycle constraints?
Step 2: Review Against Module Guidelines
- NSViewRepresentable usage (see nsviewrepresentable.md)
- Hosting controllers (see hosting-controllers.md)
- State management (see state-management.md)
Step 3: Provide Structured Feedback
For each issue found:
- Issue: Describe the bridging problem
- Impact: Memory leak, state desync, layout glitch, etc.
- Fix: Concrete code showing the correct approach
- Pattern: Reference the applicable bridging pattern
Common Pitfalls
1. 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
}
2. Missing Dismantling
// Wrong - observer never removed
static func dismantleNSView(_ nsView: NSView, coordinator: Coordinator) {
// Empty - leaks observer!
}
// Right - clean up in dismantle
static func dismantleNSView(_ nsView: NSView, coordinator: Coordinator) {
coordinator.observation?.invalidate()
NotificationCenter.default.removeObserver(coordinator)
}
3. Forcing Layout in Wrong Phase
// Wrong - layout during makeNSView
func makeNSView(context: Context) -> NSView {
let view = NSView()
view.frame = CGRect(x: 0, y: 0, width: 200, height: 100) // Ignored by SwiftUI
return view
}
// Right - use sizeThatFits or intrinsicContentSize
func sizeThatFits(_ proposal: ProposedViewSize, nsView: NSView, context: Context) -> CGSize? {
CGSize(width: proposal.width ?? 200, height: 100)
}
Module References
Load these modules as needed:
-
NSViewRepresentable:
nsviewrepresentable.md- Full protocol implementation
- Coordinator pattern
- Layout integration with sizeThatFits
-
Hosting Controllers:
hosting-controllers.md- NSHostingView and NSHostingController
- Window management
- Incremental SwiftUI adoption
-
State Management:
state-management.md- @Observable bridging
- Combine pipelines
- Notification-based communication
Response Guidelines
- Always specify the minimum macOS version for APIs used
- Provide both AppKit and SwiftUI sides of the bridge
- Highlight memory management and cleanup requirements
- Prefer @Observable (macOS 14+) over ObservableObject when possible
- Warn about common retain cycles in coordinators
From the file to a first result
The download contains exactly the content displayed on this page. This copy may differ from the latest version in the source repository.
View the source and supporting filesThis download contains SKILL.md only. Any scripts, references, templates and dependencies are not included. Get the required files from the source, preserving their directory structure, before continuing.
1. Download the file
Download SKILL.mdFrom the root of a test project, save the file as .skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md, or use the command below. This folder is for inspecting the skill before installation.
Command for macOS/Linux or WSL: requires a POSIX shell and curl. On Windows without WSL, use the download button and create the folder manually.
mkdir -p '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1' && curl --fail --show-error --location 'https://skills-guides.com/api/skills/appkit-swiftui-bridge-expert-mrx3xxb1/download' --output '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md.part' && mv '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md.part' '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md'2. Check prerequisites
Read SKILL.md before using it. If it references scripts or external services, inspect them and prepare the required access in your test environment.
No recognized prerequisites section in this file. This does not mean it is self-contained: libraries, tools and access requirements may be mentioned elsewhere in the content or source repository.
The platforms on this page are catalog indications. The paths below follow tool documentation; they do not prove this skill has been run in those tools. No minimum tool version is confirmed for this listing.
3. Load the skill
After inspection, copy the complete folder into your project using one of the commands below, then open a new tool session. The command stops if a folder with the same name already exists: compare the files before replacing it.
Claude Code
test -f '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md' && test -s '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md' && mkdir -p '.claude/skills' && test ! -e '.claude/skills/appkit-swiftui-bridge' && cp -R '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1' '.claude/skills/appkit-swiftui-bridge'Cursor
test -f '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md' && test -s '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md' && mkdir -p '.cursor/skills' && test ! -e '.cursor/skills/appkit-swiftui-bridge' && cp -R '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1' '.cursor/skills/appkit-swiftui-bridge'Codex
test -f '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md' && test -s '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md' && mkdir -p '.agents/skills' && test ! -e '.agents/skills/appkit-swiftui-bridge' && cp -R '.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1' '.agents/skills/appkit-swiftui-bridge'OpenSkills
OpenSkills must already be installed. The local install/read procedure is checked with OpenSkills 1.5.0, which requires Node.js ≥ 20.6.0. Catalog slugs are not resolved automatically.
Official OpenSkills installationopenskills install './.skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1'openskills read 'appkit-swiftui-bridge-expert-mrx3xxb1'Reading should display the installed file content and its base directory. It does not run the skill or install its dependencies.
For an agent that reads AGENTS.md, then sync the index. This command changes AGENTS.md: review the diff before using it.
openskills syncManual method or another tool: attach SKILL.md to a conversation, or open it in an agent that can read files. Include any required supporting resources. No universal folder is recognized by every tool.
4. Try a first task
Use a short, synthetic input: an API endpoint, a small document or an interface brief. In a new conversation, attach the file or give the agent its path, then adapt this request:
Read .skill-downloads/appkit-swiftui-bridge-expert-mrx3xxb1/SKILL.md and apply its instructions to this example: [describe a test input]. Identify any missing files, dependencies or access. Produce the result requested by the skill without inventing data or running unreviewed scripts.Expected result: output matching the skill instructions, or a precise list of missing prerequisites. A read confirmation alone does not validate a first use. If an external resource is unavailable, that path remains untested.
React Hook Form Best Practices
Development
Master React Hook Form: avoid anti-patterns, manage subscriptions, and handle reset, dirty state, and controlled inputs correctly.
Emotion to Mantine Migration
Development
Migrate Emotion styled-components to Mantine components with style props and CSS modules. Use when converting .styled.tsx files or removing @emotion imports.
Scope Creep Detector
Development
Analyzes git diffs against a stated intent to detect scope creep, unrelated files, broad PRs, and oversized changes, then suggests keep, split, or justify actions.