| name | swiftui-examples |
| description | Ground SwiftUI code in ranked examples from shipping macOS apps before choosing APIs, argument shapes, or implementation patterns. |
| license | MIT |
Bundled resource root
Let <swiftui-plugin-root> be the absolute plugin directory two levels above this SKILL.md. Resolve that path before running commands or opening shared references. When these instructions say swiftui-ctx, invoke <swiftui-plugin-root>/scripts/swiftui-ctx; do not assume the command is on PATH.
Compatibility: Requires macOS with a Swift 6 toolchain (Xcode) to build the bundled CLI on first run; the file command needs network access. Using the CLI needs nothing else (the catalog is bundled).
swiftui-examples โ drive swiftui-ctx
swiftui-ctx answers "how do shipping macOS apps actually write this SwiftUI?" from 1,857 analyzed
production repos, quality-ranked (author authority + stars + modernity) with GitHub permalinks. It is the
practice layer; the spec is sosumi.ai (official docs), which every result links to.
swiftui-ctx is the bundled wrapper at <swiftui-plugin-root>/scripts/swiftui-ctx โ it downloads or builds the CLI on
first run and points it at the catalog automatically. Inside the plugin call "<swiftui-plugin-root>/scripts/swiftui-ctx" <cmd>;
from a clone, run make install once to put swiftui-ctx on PATH. Both self-locate the catalog.
The rule (do this first, every time)
Writing SwiftUI from memory is how LLMs ship hallucinated and deprecated APIs โ and it happens on routine code, not just exotic APIs. This skill exists to stop that. So:
- Announce it. Before writing any SwiftUI, say: "Using swiftui-examples to ground this in production code." (Committing out loud is what keeps you in the loop instead of reverting to memory.)
- Query before you write. Do not emit a SwiftUI type, modifier, or property wrapper from memory. Run
swiftui-ctx lookup <api> (or recipe/search) first. No exceptions โ even for APIs you "know," because the catalog also tells you the current idiom and whether your call is deprecated.
- Do not return code until you have
file --smart output in context. A lookup line is a fragment; file --smart gives the real, compilable enclosing view. Returning the fragment is the #1 failure mode โ don't.
Why this beats your memory (the payoff)
| Querying gives you | Skipping it risks |
|---|
The current idiom (e.g. foregroundStyle, NavigationStack, @Observable) | Shipping a deprecated API (foregroundColor, NavigationView) โ flagged in 1,000+ real repos |
| The consensus argument shape real apps use | Guessing an overload that compiles but isn't idiomatic |
| A compilable enclosing view from a high-authority app | A plausible-looking fragment that doesn't actually work |
| macOS-correct patterns (MenuBarExtra, Settings, NSViewRepresentable bridges) | iOS-isms that don't fit a Mac app |
| A GitHub permalink the user can verify | Unverifiable, confidently-wrong code |
Full rationale + how ranking works (so you can trust recommended/consensus) โ references/why-this-matters.md.
When to use โ fire on ANY of these
- About to write/edit a SwiftUI call: a
View/Scene type, a .modifier(...), @State/@Binding/@Observable/@Environment/@AppStorage/@FocusState, a gesture, a Command, a style.
- Unsure of an argument shape or which overload; verifying the current idiom for an API before you write it.
- Planning a SwiftUI feature (which APIs/recipes to reach for). For migrating an existing file off deprecated APIs use
swiftui-modernize; for symptoms in finished code ("state not updating", "list is slow") or a whole-codebase pass, run the relevant audit-swiftui-* skill / audit-macos-swiftui-full.
Do NOT use (and what to use instead)
- Official signatures/semantics โ sosumi.ai (the
doc: link in every result).
- Non-SwiftUI Swift (Foundation, Combine, standalone AppKit, language syntax). Xcode/build/signing config.
- iOS-only code โ only with
--platform any (the corpus is macOS-first).
First run / discovery
The CLI + catalog ship with the plugin. The bundled wrapper downloads or builds the CLI on first use and finds the
catalog automatically โ no manual paths.
CTX="<swiftui-plugin-root>/scripts/swiftui-ctx"
"$CTX" doctor
First run may take ~1-2 min (downloads a prebuilt binary, or builds from source if a Swift toolchain is present).
Names work as you write them: lookup @State, lookup .searchable, lookup frame(width:height:) all resolve.
Add --json for the machine envelope; default is human markdown ending in a literal Next: block.
The loop (non-negotiable)
- Run the first command for your situation (table below).
- Read
next_actions and run the highest-priority one โ almost always swiftui-ctx file <id> --smart.
- Only then write code. Stop after
lookup + file --smart on the recommended example; go deeper
(examples, file --full) only if the consensus shape is ambiguous for your task.
Scenario โ command playbook (situation โ first command โ required follow-up)
| Situation | First command | Then |
|---|
| Writing a call to a known API | swiftui-ctx lookup <api> | swiftui-ctx file <recommended.id> --smart |
| Choosing the argument shape / overload | swiftui-ctx lookup <api> โ read consensus | swiftui-ctx examples <api> --shape "(โฆ)" |
| Is it current / deprecated? | swiftui-ctx deprecated <api> | if deprecated โ swiftui-ctx lookup <replacement> |
| Building a known pattern | swiftui-ctx recipe <name> | swiftui-ctx file <example.id> --smart |
| Planning a feature (unknown APIs) | swiftui-ctx search "<intent>" | swiftui-ctx lookup <each candidate> |
(Migrating a file off deprecated APIs โ swiftui-modernize. Reviewing/auditing finished code or a whole project โ the audit-swiftui-* skills / audit-macos-swiftui-full. This skill is the write/lookup layer those skills call for the consensus shape.)
Worked transcripts for each row + the recipe list โ references/playbook.md.
Reading results (trust the ranking)
- Prefer
recommended over diverse โ it's the highest production-quality call site (authority + stars + modernity).
- Follow
consensus โ write the shape most apps use; rare shapes are edge cases.
- Never emit a
deprecated API โ use the replacement the tool gives.
co_occurs_with = APIs used disproportionately with this one (real pattern signal). low_corpus: true = thin evidence, cross-check the doc: link.
Errors โ actions (exit codes)
3 not-found โ swiftui-ctx search "<broader term>". 4 network (only file w/o --offline) โ retry once, then --offline.
5 no catalog โ STOP, tell the user, do NOT fabricate from memory. Full command/flag/field/exit contract โ references/commands.md.
Anti-patterns (don't)
- Writing the modifier first and "checking later" โ you won't; the deprecated/wrong idiom ships. Query first.
- Returning the one-line
lookup src as the answer โ it's a fragment. file --smart or it didn't happen.
- Inventing an API when
lookup 404s โ run search; if still nothing, say so and use sosumi โ never fabricate.
References
| File | Read when |
|---|
references/playbook.md | You need the worked command transcripts per scenario + the recipe catalog. |
references/commands.md | You need the exact flags, --json field schema, and exit-code contract. |
references/why-this-matters.md | You doubt the tool / want to know how ranking works and what "production-grade" means here. |