视觉画布设计
canvas-design
基于设计原则创作静态视觉作品,用于海报与品牌图形。
macos-swift-desktop【文档与办公】Build native macOS desktop applications in Swift using AppKit and SwiftUI. Use when building or modifying macOS .app bundles, NSDocument-based apps, menu bar apps, preferences windows, NSWindow/NSToolbar/NSSplitView layouts, NSMenu/NSStatusItem, Core Data/SwiftData/GRDB persistence, drag-and-drop, undo/redo, sandboxing, notarization, Sparkle auto-upd…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
Build native macOS desktop apps in Swift. This skill is topic-organized: SKILL.md is the index and routing table; detailed patterns and code live in references/.
.app bundle (AppKit, SwiftUI, or hybrid)NSDocument, FileDocument)NSStatusItem)UserDefaults, Keychain)SMAppService, Shortcuts/Intents, FileProvider, HandoffXCUIApplication, OSLog, Instruments, crash reportingIf the task is pure Swift language questions from a TypeScript/Python background, read references/swift-for-ts-devs.md.
Always use the hybrid pattern for non-trivial desktop apps. Pure SwiftUI is missing too much: custom Metal rendering, fine-grained gesture control, low-level window management, borderless/transparent windows, and multi-window coordination. Pure AppKit is verbose for forms, settings, and standard controls.
┌───────────────────────────────────────────┐
│ App lifecycle (AppKit) │
│ NSApplicationDelegate, NSWindow, │
│ NSWindowController, NSDocument │
│ │
│ ┌─────────────────────────────────────┐ │
│ │ Window chrome (SwiftUI or AppKit) │ │
│ │ Toolbar, sidebar, inspector, │ │
│ │ settings, forms │ │
│ │ │ │
│ │ ┌────────────────────────────────┐ │ │
│ │ │ Content view (custom NSView │ │ │
│ │ │ if performance-critical — │ │ │
│ │ │ Metal, text editor, canvas) │ │ │
│ │ └────────────────────────────────┘ │ │
│ └─────────────────────────────────────┘ │
└───────────────────────────────────────────┘
Rule of thumb: AppKit owns the structural shell (windows, split views, toolbars, documents). SwiftUI owns the content panels (sidebars, inspectors, settings). Performance-critical views (text editors, terminals, Metal canvases) are custom NSView subclasses embedded via NSViewRepresentable.
Full details and code: references/appkit-swiftui-hybrid.md
| If the task involves... | Read |
|---|---|
App startup, @main, NSApplicationDelegate, menu validation, file type registration | references/app-lifecycle.md |
Opening, saving, autosaving files; NSDocument / FileDocument / file coordination | references/document-apps.md |
| Menus, alerts, sheets, popovers, modals, dock badges | references/standard-ui.md |
Menu bar apps (NSStatusItem, LSUIElement, activation policy) | references/menu-bar-apps.md |
| Window geometry, multi-screen, fullscreen, frame restoration | references/windows-and-geometry.md |
Core Data / SwiftData / GRDB / UserDefaults / Keychain | references/persistence.md |
Undo/redo, drag-and-drop, pasteboard, NSOpenPanel/NSSavePanel, shortcuts, accessibility | references/user-interaction.md |
| Sandbox, entitlements, code signing, notarization, Sparkle | references/distribution.md |
XCTest, UI tests, Instruments, OSLog, signposts, crash reporting | references/testing-and-observability.md |
XPC services, SMAppService, AppIntent, NSUserActivity, FileProvider | references/system-integration.md |
AppKit+SwiftUI bridging, NSHostingView, NSViewRepresentable, coordinator pattern | references/appkit-swiftui-hybrid.md |
Metal, CAMetalLayer, infinite canvas, WKWebView embedding | references/advanced-rendering.md |
| Embedding libghostty terminal surfaces | references/libghostty-integration.md |
| Tier-1 repos to clone and study | references/reference-repos.md |
| Swift concurrency pitfalls (split isolation, Task.detached, blocking async) | references/swift-concurrency.md |
| What NOT to do | references/anti-patterns.md |
| Swift syntax from a TypeScript/Python lens | references/swift-for-ts-devs.md |
Full list with "do this instead" pointers: references/anti-patterns.md
NSPopover for menu bar UI — use NSMenu; popovers have dismissal bugs and don't feel nativeNSOutlineView without virtualization — 10k+ items hang the UI; animations can't be disabledNSOpenPanel/bookmarks — sandbox violations; fails on Mac App StoreTask.isCancelled in long-running work — tasks don't auto-cancel; background work burns CPU/batteryNSUndoManager — users expect Cmd+Z; custom stacks are fragileMTLCreateSystemDefaultDevice()!) — crash on older hardware/VMsUserDefaults or app support directory@MainActor on view controllers, view models, and anything touching UIKit/AppKit. Opt into parallelism explicitly via nonisolated or detached tasks.async/await over completion handlers. Avoid Combine for new code unless the API surface demands it.Observable macro (not ObservableObject) for SwiftUI view models on macOS 14+.func load() throws(LoadError)) for domain errors where the caller can meaningfully discriminate.async let and TaskGroup over DispatchQueue. Limit DispatchQueue to interop with C APIs that demand it.Observable, SwiftData, NavigationStack for documents, and modern SwiftUI APIs.swift package init --type executable + Package.swift with .macOS(.v14) platform)Info.plist entries: CFBundleIdentifier, LSApplicationCategoryType, NSHumanReadableCopyright, and any CFBundleDocumentTypes for document appsNSApplicationDelegate (even in SwiftUI apps via @NSApplicationDelegateAdaptor) for lifecycle hooks not exposed by SwiftUI's App protocolOSLog subsystem and categories early (Logger(subsystem: "com.you.App", category: "..."))references/distribution.mdNSDocument, NSOutlineView, menusTier-1 open-source repos to clone and study: references/reference-repos.md