Skip to content
Automation
Skill

/swiftui-ui-patterns

Best practices and example-driven guidance for building SwiftUI views and components, including navigation hierarchies, custom view modifiers, and responsive layouts with stacks and grids. Use when creating or refactoring SwiftUI UI, designing tab architecture with TabView,

From plugin
homeclaw
19620 skills7 agents4 commands

Claude Code

$ npx -y skills add omarshahine/HomeClaw --skill swiftui-ui-patterns --agent claude-code

SKILL.md

swiftui-ui-patterns.SKILL.md
name: swiftui-ui-patterns
description: Best practices and example-driven guidance for building SwiftUI views and components, including navigation hierarchies, custom view modifiers, and responsive layouts with stacks and grids. Use when creating or refactoring SwiftUI UI, designing tab architecture with TabView, composing screens with VStack/HStack, managing @State or @Binding, building declarative iOS interfaces, or needing component-specific patterns and examples.

SwiftUI UI Patterns

Quick start

Choose a track based on your goal:

Existing project

  • Identify the feature or screen and the primary interaction model (list, detail, editor, settings, tabbed).
  • Find a nearby example in the repo with `rg "TabView\("` or similar, then read the closest SwiftUI view.
  • Apply local conventions: prefer SwiftUI-native state, keep state local when possible, and use environment injection for shared dependencies.
  • Choose the relevant component reference from `references/components-index.md` and follow its guidance.
  • If the interaction reveals secondary content by dragging or scrolling the primary content away, read `references/scroll-reveal.md` before implementing gestures manually.
  • Build the view with small, focused subviews and SwiftUI-native data flow.

New project scaffolding

  • Start with `references/app-wiring.md` to wire TabView + NavigationStack + sheets.
  • Add a minimal `AppTab` and `RouterPath` based on the provided skeletons.
  • Choose the next component reference based on the UI you need first (TabView, NavigationStack, Sheets).
  • Expand the route and sheet enums as new screens are added.

General rules to follow

  • Use modern SwiftUI state (`@State`, `@Binding`, `@Observable`, `@Environment`) and avoid unnecessary view models.
  • If the deployment target includes iOS 16 or earlier and cannot use the Observation API introduced in iOS 17, fall back to `ObservableObject` with `@StateObject` for root ownership, `@ObservedObject` for injected observation, and `@EnvironmentObject` only for truly shared app-level state.
  • Prefer composition; keep views small and focused.
  • Use async/await with `.task` and explicit loading/error states. For restart, cancellation, and debouncing guidance, read `references/async-state.md`.
  • Keep shared app services in `@Environment`, but prefer explicit initializer injection for feature-local dependencies and models. For root wiring patterns, read `references/app-wiring.md`.
  • Prefer the newest SwiftUI API that fits the deployment target and call out the minimum OS whenever a pattern depends on it.
  • Maintain existing legacy patterns only when editing legacy files.
  • Follow the project's formatter and style guide.
  • **Sheets**: Prefer `.sheet(item:)` over `.sheet(isPresented:)` when state represents a selected model. Avoid `if let` inside a sheet body. Sheets should own their actions and call `dismiss()` internally instead of forwarding `onCancel`/`onConfirm` closures.
  • **Scroll-driven reveals**: Prefer deriving a normalized progress value from scroll offset and driving the visual state from that single source of truth. Avoid parallel gesture state machines unless scroll alone cannot express the interaction.

State ownership summary

Use the narrowest state tool that matches the ownership model:

| Scenario | Preferred pattern | | --- | --- | | Local UI state owned by one view | `@State` | | Child mutates parent-owned value state | `@Binding` | | Root-owned reference model on iOS 17+ | `@State` with an `@Observable` type | | Child reads or mutates an injected `@Observable` model on iOS 17+ | Pass it explicitly as a stored property | | Shared app service or configuration | `@Environment(Type.self)` | | Legacy reference model on iOS 16 and earlier | `@StateObject` at the root, `@ObservedObject` when injected |

Choose the ownership location first, then pick the wrapper. Do not introduce a reference model when plain value state is enough.

Cross-cutting references

  • In addition to the references below, use web search to consult current Apple Developer documentation when SwiftUI APIs, availability, or platform guidance may have changed.
  • `references/navigationstack.md`: navigation ownership, per-tab history, and enum routing.
  • `references/sheets.md`: centralized modal presentation and enum-driven sheets.
  • `references/deeplinks.md`: URL handling and routing external links into app destinations.
  • `references/app-wiring.md`: root dependency graph, environment usage, and app shell wiring.
  • `references/async-state.md`: `.task`, `.task(id:)`, cancellation, debouncing, and async UI state.
  • `references/previews.md`: `#Preview`, fixtures, mock environments, and isolated preview setup.
  • `references/performance.md`: stable identity, observation scope, lazy containers, and render-cost guardrails.

Anti-patterns

  • Giant views that mix layout, business logic, networking, routing, and formatting in one file.
  • Multiple boolean flags for mutually exclusive sheets, alerts, or navigation destinations.
  • Live service calls directly inside `body`-driven code paths instead of view lifecycle hooks or injected models/services.
  • Reaching for `AnyView` to work around type mismatches that should be solved with better composition.
  • Defaulting every shared dependency to `@EnvironmentObject` or a global router without a clear ownership reason.

Workflow for a new SwiftUI view

1. Define the view's state, ownership location, and minimum OS assumptions before writing UI code. 2. Identify which dependencies belong in `@Environment` and which should stay as explicit initializer inputs. 3. Sketch the view hierarchy, routing model, and presentation points; extract repeated parts into subviews. For complex navigation, read `references/navigationstack.md`, `references/sheets.md`, or `references/deeplinks.md`. **Build and verify no compiler errors before proceeding.** 4. Implement async loading with `.task` or `.task(id:)`, plus explicit loading and e

Read more
@omarshahine
Ships withhomeclaw

HomeKit smart home control via MCP — lights, locks, thermostats, and scenes for Claude Desktop, Claude Code, and OpenClaw

19620 skills7 agents
Get the whole plugin

Stars on GitHub

Momentum

stars in total
196
Star history of omarshahine/HomeClaw on GitHub, a chart by star-history.com

Other skills on homeclaw.

app-resizability

app-resizability

Use when an app's layout must adapt to a window that changes size while the app runs, or when an app must support more than one…

ios-app-intents

ios-app-intents

Design and implement App Intents, app entities, and App Shortcuts for iOS apps so useful actions and content are available to…

ios-debugger-agent

ios-debugger-agent

Use XcodeBuildMCP to build, run, launch, and debug the current iOS project on a booted simulator. Trigger when asked to run an…

ios-memgraph-leaks

ios-memgraph-leaks

Capture, inspect, compare, and root-cause iOS memory graph leaks using Apple's leaks and memgraph tools. Use when debugging…

spm-build-analysis

spm-build-analysis

Analyze Swift Package Manager dependencies, package plugins, module variants, and CI-oriented build overhead that slow Xcode…

More skills from other plugins.

agent-builder

agent-builder

Load immediately after an Agent intent, before the first agent_builder_* call. Governs how you create, configure, test, and…

n8n3w209k
@n8n-io@n8n-ioInstall Skill
browser-use

browser-use

Direct browser control via CDP for web interaction: automation, scraping, testing, screenshots, and site/app work. Also covers…

@browser-use@browser-useInstall Skill
add-anydoc

add-anydoc

Add local office-document-to-Markdown conversion to NanoClaw agent containers with the pinned Firecrawl AnyDoc CLI. Use when…

nanoclaw12d31k
@nanocoai@nanocoaiInstall Skill

Questions about swiftui-ui-patterns.

Which coding agents can use swiftui-ui-patterns?
swiftui-ui-patterns installs in Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, OpenCode and Windsurf with the skills CLI, using each agent's flag shown on this page. Flowy's auto-invocation, which fires a skill when your prompt matches, runs in Claude Code only.