swiftui-patterns
Skill4.3k starsChanged 5 months agoMITView on GitHub
Best practices and example-driven guidance for building native macOS SwiftUI scenes and components, including windows, commands, toolbars, settings, split views, inspectors, menu bar extras, and keyboard-driven workflows. Use when creating or refactoring macOS SwiftUI UI, choosing scene types, wiring menus or settings, or needing desktop-specific component patterns and examples.
15 other projects use a version of this, 1 of them edited.
Trending
More talk lately.about the whole repository
Most recently taken up by
- templetongroup/radianttheir own version, first seen Sep 17, 2026
- SamuelNDCE/claude-super-skill-librarytheir own version, first seen Aug 1, 2026
- dpearson2699/swift-ios-skillstheir own version, first seen Jul 13, 2026
- ahmed3elshaer/everything-claude-code-mobiletheir own version, first seen Jun 14, 2026
- georgekhananaev/claude-skills-vaulttheir own version, first seen May 25, 2026
- openai/pluginsedited, first seen May 13, 2026
Who's talking about robinebers/openusage
- A Hacker News story“OpenUsage: Track all your AI usage, in one panel”Hacker News · Apr 30, 2026 · 2 points
- @github-trending-js.bsky.social“📦 robinebers / openusage ⭐ 1,831 (+53) 🗒 JavaScript Burning through your subscriptions too fast? Paying …”Bluesky · Apr 12, 2026 · 1 likes
- @mikestaub2.bsky.social“This is a useful too to track your AI agent usage: github.com/robinebers/o...”Bluesky · Feb 3, 2026 · 1 likes
- XusBadia/altillo“Upstream openusage: cambios en proveedores”GitHub · Oct 5, 2026
- sudosubin/agents.nix“agent-skills.github.robinebers.openusage: 0.7.12 → 0.7.13”GitHub · Oct 3, 2026
The biggest 5 of 26 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 26
Talked about on GitHub, Bluesky and Hacker News (26 times).
On GitHub · 23
- Oct 5, 2026Upstream openusage: cambios en proveedores — XusBadia/altillo0 reactions
- Oct 3, 2026agent-skills.github.robinebers.openusage: 0.7.12 → 0.7.13 — sudosubin/agents.nix0 reactions
- Oct 3, 2026Z.ai GLM Coding Plan detected but usage resources are empty — LuigiElleBalotta/AIUsage.NET0 reactions
- Oct 1, 2026agent-skills.github.robinebers.openusage: init at 0.7.12 — sudosubin/agents.nix0 reactions
- Sep 26, 2026[quota-watch] 2026-09-26 — Claude'un oauth/usage'ı artık User-Agent'a göre dallanıyor (cedar_ember); Codex refresh token'ının tek kullanımlık olduğu doğrulandı — erayendes/mimir0 reactions
18 more on GitHub
- Sep 24, 2026usage API が 429 を返し続けると、入札も回復待ちの判定も効かなくなり、自動の着手が止まり、走っている run も stall として止められうる — maimuzo/continuo0 reactions · 130 comments
- Sep 19, 2026[quota-watch] 2026-09-19 — Claude CLAUDE_CONFIG_DIR hiç okunmuyor; Codex kendi auth.json'a token yazıyor; yeni bir oauth/profile ucu var — erayendes/mimir0 reactions · 4 comments
- Sep 16, 2026feat(cursor): Cursor card — plan usage by session token — Rast53/usage-board0 reactions · 1 comment
- Sep 13, 2026[P2][RELIABILITY][DOCUMENTATION] Complete or retire the expired Prometheus counter migration — Reese-max/lobsterpulse0 reactions · 2 comments
- Sep 9, 2026feat(muse) - Add muse-code from Meta as provider — janekbaraniewski/openusage0 reactions · 5 comments
- Sep 5, 2026[quota-watch] 2026-09-05 — Antigravity grup-kota alan adları iki bağımsız rakipte doğrulandı; Claude web endpoint'i Cloudflare engeline takılabiliyor — erayendes/mimir0 reactions · 1 comment
- Aug 29, 2026[quota-watch] 2026-08-29 — Codex 5 saatlik pencere Plus için canlıya geçti; Antigravity grup-kota alan adlarında olası uyuşmazlık — erayendes/mimir0 reactions · 3 comments
- Aug 28, 2026feat(providers): add grok quota monitoring — medokin/ReservePane0 reactions
- Aug 26, 2026feat(providers): add OpenCode Go quota monitoring — medokin/ReservePane0 reactions
- Aug 13, 2026Document OpenCode Go Rate limits from GET /zen/go/v1/usage — lidge-jun/opencodex0 reactions · 4 comments
- Aug 10, 2026[quota-watch] 2026-08-10 — Antigravity: olası app/bundle adı değişikliği ve RetrieveUserQuotaSummary'de auth race raporu (düşük güven) — erayendes/mimir0 reactions · 3 comments
- Aug 4, 2026feat(ai): add Cursor personal usage reporting — can1357/oh-my-pi0 reactions
- Jul 13, 2026openusage: 0.6.13 -> 0.7.5, add Br1ght0ne to maintainers — NixOS/nixpkgs0 reactions
- Jun 26, 2026Wire SQLite reader into getSummary() to fix usage accuracy drift (#23 root cause) — ltmoerdani/opencode-copilot-chat0 reactions · 1 comment
- Apr 30, 2026[feature]: Opencode Go without workspace ID and auth cookie — slkiser/opencode-quota0 reactions · 4 comments
- Apr 10, 2026Upstream merge — Rana-Faraz/usage-tray-windows0 reactions · 1 comment
- Apr 7, 2026limit what provider models show up (includes PR) — Rana-Faraz/usage-tray-windows0 reactions · 1 comment
- Apr 5, 2026openusage: init at 0.6.13 — NixOS/nixpkgs0 reactions · 2 comments
On Bluesky · 2
- Apr 12, 2026📦 robinebers / openusage ⭐ 1,831 (+53) 🗒 JavaScript Burning through your subscriptions too fast? Paying for stuff you never use? Stop… — @github-trending-js.bsky.social1 likes and repost
- Feb 3, 2026This is a useful too to track your AI agent usage: github.com/robinebers/o... — @mikestaub2.bsky.social1 likes and repost
On Hacker News · 1
- Apr 30, 2026OpenUsage: Track all your AI usage, in one panel2 points
Used with
Projects with it also use swift-protocol-di-testing, swift-actor-persistence and 10 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
InfopibeSkillswift-protocol-di-testing
Protocol-based dependency injection for testable Swift code — mock file system, network, and external APIs using focused protocols and Swift Testing.
Also in 5 projects that use this
InfopibeSkillswift-actor-persistence
Thread-safe data persistence in Swift using actors — in-memory cache with file-backed storage, eliminating data races by design.
Also in 5 projects that use this
saxon-ySkillconfigure-ecc
Interactive installer for Everything Claude Code — guides users through selecting and installing skills and rules to user-level or project-level directories, verifies paths, and optionally optimizes installed files.
Also in 4 projects that use this
FaisalAlqarniSkillspringboot-tdd
Test-driven development for Spring Boot using JUnit 5, Mockito, MockMvc, Testcontainers, and JaCoCo. Use when adding features, fixing bugs, or refactoring.
Also in 4 projects that use this
FaisalAlqarniSkilldjango-verification
Verification loop for Django projects: migrations, linting, tests with coverage, security scans, and deployment readiness checks before release or PR.
Also in 4 projects that use this
- +7 more from Infopibe
Other versions15 projects use a version of this.
Word for word · 0
None found.
Edited · 1
- openai/plugins★ 7.3k95% same
Wrote their own version · 14
- xu-xiang/everything-claude-code-zh★ 2ksame name
- dpearson2699/swift-ios-skills★ 1.2ksame name
- loulanyue/awesome-claude-notes★ 272same name
- tpavanipradeep/everything-claude-code★ 134same name
- templetongroup/radiant★ 113same name
- Jamkris/everything-gemini-code★ 87same name
- ahmed3elshaer/everything-claude-code-mobile★ 66same name
- georgekhananaev/claude-skills-vault★ 28same name
- Infopibe/everything-claude-code★ 8same name
- Cyvid7-Darus10/claude-code-config★ 2same name
4 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository29 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .cursor/rules/openusage-preview-launch.mdcCursor rule
- appkit-interopSkill
- build-and-run-macos-appSkill
- build-run-debugSkill
- fix-codesign-errorSkill
- liquid-glassSkill
- macos-appkit-interopSkill
- macos-build-run-debugSkill
- macos-liquid-glassSkill
- macos-packaging-notarizationSkill
- macos-signing-entitlementsSkill
- macos-swiftpmSkill
- macos-swiftui-patternsSkill
- macos-telemetrySkill
- macos-test-triageSkill
- macos-view-refactorSkill
- macos-window-managementSkill
- packaging-notarizationSkill
- pricing-updateSkill
- release-swiftSkill
- signing-entitlementsSkill
- swiftpm-macosSkill
- telemetrySkill
- test-macos-appSkill
- test-triageSkill
- view-refactorSkill
- window-managementSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
24 rules. 0 are common, 15 are distinctive, and 9 are very specific to this project.
0
Common
Most of the 13 edited versions we read keep these.
15
Distinctive
This author's own choices. Worth a look.
9
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Read the nearest existing scene or root view before inventing a new desktop structure.
- Very specific: line 17
If SwiftUI cannot express the required platform behavior cleanly, use the appkit-interop skill rather than forcing a shaky workaround.
- Distinctive: line 23
Before creating the scaffold, check whether the workspace is already inside a git repo with git rev-parse --is-inside-work-tree.
- Distinctive: line 27
Use a single Swift file only for tiny throwaway examples or snippets: roughly under 50 lines, one screen, no persistence, no …
- Distinctive: line 44
Keep files small and named after the primary type they contain.
- Distinctive: line 50
Before writing the full UI:
- Distinctive: line 55
Create the folder structure before filling in the UI.
- Very specific: line 56
Keep script/build_and_run.sh separate from app source.
- Very specific: line 61
Keep scenes explicit. A separate settings window, utility window, or menu bar extra should be modeled as its own scene, not hidden inside …
- Very specific: line 62
Prefer system desktop affordances: commands, toolbars, sidebars, inspectors, contextual menus, and searchable.
- Distinctive: line 65
Prefer system-adaptive colors, materials, and semantic foreground styles.
- Very specific: line 67
Use @SceneStorage for per-window ephemeral state and @AppStorage for durable user preferences.
- Distinctive: line 68
Keep selection state explicit and stable.
- Very specific: line 69
Prefer NavigationSplitView or a deliberate manual split layout over iOS-style stacked flows when the app benefits from always-visible …
- Distinctive: line 71
Keep primary actions discoverable from both UI chrome and keyboard shortcuts when appropriate.
- Very specific: line 72
Use SwiftUI-native scenes and views first.
- Distinctive: line 76
Prefer a native source-list row shape:
- Distinctive: line 112
Prefer letting the sidebar and split container use system backgrounds, while applying custom surfaces only to detail cards or inspector …
- Distinctive: line 135
Avoid painting the sidebar and root split panes with opaque custom fills by default:
- Distinctive: line 153
Use the narrowest state tool that matches the ownership model:
- Distinctive: line 198
Create the file/folder structure for app entrypoint, root layout, feature views, models, stores, services, and support helpers.
- Distinctive: line 200
Add keyboard shortcuts and menu or toolbar exposure for actions that matter on desktop.
- Very specific: line 205
Use references/components-index.md as the entry point.
- Very specific: line 209
when to fall back to appkit-interop
“Common” is measured: kept by at least 6 in 10 of the 13 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
SwiftUI Patterns
Quick Start
Choose a track based on your goal:
Existing project
- Identify the feature or scene and the primary interaction model: document, editor, sidebar-detail, utility window, settings, or menu bar extra.
- Read the nearest existing scene or root view before inventing a new desktop structure.
- Choose the relevant reference from
references/components-index.md. - If SwiftUI cannot express the required platform behavior cleanly, use the
appkit-interopskill rather than forcing a shaky workaround.
New app scaffolding
- Choose the scene model first:
WindowGroup,Window,Settings,MenuBarExtra, orDocumentGroup. - If the app combines a normal main window and a
MenuBarExtra, useWindowGroup(..., id:)for the primary window when it should appear at launch. TreatWindow(...)as a better fit for auxiliary/on-demand singleton windows; in menu-bar-heavy apps, aWindow(...)scene may not present the main window automatically at launch. - Before creating the scaffold, check whether the workspace is already inside a git repo with
git rev-parse --is-inside-work-tree. If not, rungit initat the project root so git-backed editor features unlock from the start. Do not initialize a nested repo inside an existing parent checkout. - For a new app scaffold, also create one project-local
script/build_and_run.shso the app has a single kill + build + run entrypoint from the start. Use the exact bootstrap contract frombuild-run-debugand itsreferences/build-script.mdfile rather than inventing a second variant here. - Decide which state is app-wide, scene-scoped, or window-scoped before writing views.
- Sketch file and module boundaries before writing the full UI. For any non-trivial app, create the folder structure first and split files by responsibility from the start.
- Use a single Swift file only for tiny throwaway examples or snippets: roughly under 50 lines, one screen, no persistence, no networking/process client, and no reusable models. Anything beyond that should be multi-file immediately.
- Use system-adaptive colors and materials by default (
Color.primary,Color.secondary, semantic foreground styles,.regularMaterial, etc.) so the app follows Light/Dark mode automatically. Do not hardcode white or light backgrounds unless the user explicitly asks for a fixed theme, and do not reach for opaquewindowBackgroundColorfills for root panes by default. - Pick the references for the first feature surface you need: windowing, commands, split layouts, or settings.
New App File Structure
For any non-trivial macOS app, start with this shape instead of putting the app, all views, models, stores, services, and helpers in one Swift file:
App/<AppName>App.swift: the@mainapp type andAppDelegateonly.Views/ContentView.swift: root layout and high-level composition only.Views/SidebarView.swift,Views/DetailView.swift,Views/ComposerView.swift, etc.: feature views named after their primary type.Models/*.swift: value models, identifiers, and selection enums.Stores/*.swift: persistence and state stores.Services/*.swift: app-server, network, process, or platform clients.Support/*.swift: small formatters, resolvers, extensions, and glue helpers.
Keep files small and named after the primary type they contain. If a file starts collecting unrelated views, models, stores, networking clients, and helper extensions, split it before adding more behavior.
Pre-Edit Checklist For New App Scaffolds
Before writing the full UI:
- Choose the scene model.
- Choose state ownership: app-wide, scene-scoped, window-scoped, or view-local.
- Sketch file and module boundaries.
- Create the folder structure before filling in the UI.
- Keep
script/build_and_run.shseparate from app source.
General Rules To Follow
- Design for pointer, keyboard, menus, and multiple windows.
- Keep scenes explicit. A separate settings window, utility window, or menu bar extra should be modeled as its own scene, not hidden inside one monolithic
ContentView. - Prefer system desktop affordances:
commands, toolbars, sidebars, inspectors, contextual menus, andsearchable. - For menu bar apps, keep
MenuBarExtraitem titles and action labels short and scannable. Cap visible menu item text at 30 characters; if source content is longer, truncate or summarize it before rendering and open the full content in a dedicated window or detail surface. - If a
MenuBarExtraapp should still behave like a regular Dock app with a visible main window/process, install anNSApplicationDelegatevia@NSApplicationDelegateAdaptor, callNSApp.setActivationPolicy(.regular)during launch, and activate the app withNSApp.activate(ignoringOtherApps: true). If the app is intentionally menu-bar-only, document that.accessory/ no-Dock behavior is a deliberate product choice. - Prefer system-adaptive colors, materials, and semantic foreground styles. Avoid fixed white/light backgrounds in scaffolding and examples unless the requested design explicitly calls for a custom non-adaptive theme.
- Do not paint
NavigationSplitViewsidebars or root window panes with opaque customColor(...)orColor(nsColor: .windowBackgroundColor)fills by default. Prefer native macOS sidebar/window materials and system-provided backgrounds unless the user explicitly asks for a custom opaque surface. In sidebar-detail-inspector layouts, let the sidebar keep the standard source-list/material appearance and reserve custom backgrounds for detail or inspector content cards where needed. - Use
@SceneStoragefor per-window ephemeral state and@AppStoragefor durable user preferences. - Keep selection state explicit and stable. macOS layouts often pivot around sidebar selection rather than push navigation.
- Prefer
NavigationSplitViewor a deliberate manual split layout over iOS-style stacked flows when the app benefits from always-visible structure. - For
List(...).listStyle(.sidebar)andNavigationSplitViewsidebars, prefer flat native rows with standard system selection/highlight behavior. Keep rows visually lightweight and Mail-like: at most one leading icon, one strong title line, and one optional secondary detail line in.secondary. Avoid stacked metadata rows, repeated inline utility icons, or dense multi-column status text in the sidebar. Reserve card-style and metadata-heavy surfaces for detail or inspector panes unless the user explicitly asks for a highly custom sidebar treatment. - Keep primary actions discoverable from both UI chrome and keyboard shortcuts when appropriate.
- Use SwiftUI-native scenes and views first. If you need low-level window, responder-chain, text system, or panel control, switch to
appkit-interop.
Recommended Sidebar Row Pattern
Prefer a native source-list row shape:
List(selection: $selection) {
ForEach(items) { item in
HStack(spacing: 10) {
Image(systemName: item.systemImage)
.foregroundStyle(.secondary)
.frame(width: 16)
VStack(alignment: .leading, spacing: 2) {
Text(item.title)
.lineLimit(1)
if let detail = item.detail {
Text(detail)
.font(.caption)
.foregroundStyle(.secondary)
.lineLimit(1)
}
}
}
.tag(item.id)
}
}
.listStyle(.sidebar)This keeps selection, highlight, spacing, and scanability aligned with standard macOS sidebars. Keep each row to one icon maximum and one or two text lines maximum, with the second line reserved for a short detail label. Use richer card treatments and denser metadata in the detail or inspector content, not in every sidebar row.
Recommended Split-View Background Pattern
Prefer letting the sidebar and split container use system backgrounds, while applying custom surfaces only to detail cards or inspector sections:
NavigationSplitView {
List(selection: $selection) {
ForEach(items) { item in
Label(item.title, systemImage: item.systemImage)
.tag(item.id)
}
}
.listStyle(.sidebar)
} detail: {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
DetailSummaryCard(item: selectedItem)
DetailMetricsCard(item: selectedItem)
}
.padding()
}
}Avoid painting the sidebar and root split panes with opaque custom fills by default:
NavigationSplitView {
List(items) { item in
SidebarCardRow(item: item)
}
.listStyle(.sidebar)
.background(Color(nsColor: .windowBackgroundColor))
} detail: {
DetailView(item: selectedItem)
.background(Color(.white))
}State Ownership Summary
Use the narrowest state tool that matches the ownership model:
| Scenario | Preferred pattern |
| Local view or control state | @State |
| Child mutates parent-owned value state | @Binding |
| Root-owned reference model on macOS 14+ | @State with an @Observable type |
Child reads or mutates an injected @Observable model | Pass it explicitly as a stored property |
| Window-scoped ephemeral selection or expansion state | @SceneStorage when practical, otherwise scene-owned @State |
| Shared user preference | @AppStorage |
| Shared app service or configuration | @Environment(Type.self) |
| Legacy reference model on older targets | @StateObject at the owner and @ObservedObject when injected |
Choose the ownership location first, then the wrapper. Do not turn simple desktop state into a view model by reflex.
Cross-Cutting References
references/components-index.md: entry point for scene and component guidance.references/windowing.md: choosing betweenWindowGroup,Window,DocumentGroup, and window-opening patterns.references/settings.md: dedicated settings scenes,SettingsLink, and preference layouts.references/commands-menus.md: command menus, keyboard shortcuts, focused values, and desktop action routing.references/split-inspectors.md: sidebars, split views, selection-driven layout, and inspectors.references/menu-bar-extra.md: menu bar extra structure and when it fits.
Anti-Patterns
- One huge
ContentViewpretending the whole app is a single screen. - A single Swift file containing the
@mainapp, all views, models, stores, networking/process clients, formatters, and extensions. This is acceptable only for tiny throwaway snippets under the new-app threshold above. - Touch-first interaction models ported directly from iOS without desktop affordances.
- Hiding core actions behind gestures with no menu, toolbar, or keyboard path.
- Building a menu-bar-plus-window app around only a
Window(...)scene and then expecting the main window to appear at launch. UseWindowGroup(..., id:)for the primary launch window and reserveWindow(...)for auxiliary/on-demand windows. - Rendering full unbounded document titles, prompts, or message text directly inside a menu bar extra. Menu item labels should stay at or below 30 characters, with longer content moved into a dedicated window or detail view.
- Treating settings as another navigation destination in the main content window.
- Hardcoding
.background(.white),Color.white, or a fixed light palette in a brand-new scaffold without an explicit design requirement. - Wrapping each sidebar item in large rounded custom cards inside a
.sidebarlist, which fights native source-list density, alignment, and selection behavior unless the user explicitly asked for a bespoke visual sidebar. - Building sidebar rows with multiple repeated icons, three or more text lines, or a dense strip of inline metadata counters/timestamps/models. Keep the sidebar row to one icon and one or two text lines, then move richer metadata into the detail pane.
- Painting
NavigationSplitViewsidebars or root window panes with opaque custom color fills by default, instead of letting the sidebar use native source-list/material appearance and reserving custom backgrounds for actual content cards. - Using push navigation for layouts that want stable sidebar selection and detail panes.
- Reaching for AppKit before the SwiftUI scene and command APIs have been used properly.
Workflow For A New macOS Scene Or View
- Define the scene type and ownership model before writing child views.
- Decide which actions live in content, toolbars, commands, inspectors, or settings.
- Sketch the selection model and layout: sidebar-detail, editor-inspector, document window, or utility window.
- Create the file/folder structure for app entrypoint, root layout, feature views, models, stores, services, and support helpers.
- Build with small, focused subviews and explicit inputs rather than giant computed fragments.
- Add keyboard shortcuts and menu or toolbar exposure for actions that matter on desktop.
- Validate the flow with a build and a quick usability pass: multiwindow assumptions, settings entry points, and selection stability.
Component References
Use references/components-index.md as the entry point. Each component reference should include:
- intent and best-fit scenarios
- minimal usage pattern with desktop conventions
- pitfalls and discoverability notes
- when to fall back to
appkit-interop
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

