jpskill.com
🛠️ 開発・MCP コミュニティ 🔴 エンジニア向け 👤 エンジニア・AI開発者

🛠️ SwiftuiUIパターン集

swiftui-ui-patterns

iPhoneアプリなどの画面を効率的かつ使いやすく設計

⏱ MCPサーバー実装 1日 → 2時間

📺 まず動画で見る(YouTube)

▶ 【衝撃】最強のAIエージェント「Claude Code」の最新機能・使い方・プログラミングをAIで効率化する超実践術を解説! ↗

※ jpskill.com 編集部が参考用に選んだ動画です。動画の内容と Skill の挙動は厳密には一致しないことがあります。

📜 元の英語説明(参考)

Apply proven SwiftUI UI patterns for navigation, sheets, async state, and reusable screens.

🇯🇵 日本人クリエイター向け解説

一言でいうと

iPhoneアプリなどの画面を効率的かつ使いやすく設計

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o swiftui-ui-patterns.zip https://jpskill.com/download/3561.zip && unzip -o swiftui-ui-patterns.zip && rm swiftui-ui-patterns.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/3561.zip -OutFile "$d\swiftui-ui-patterns.zip"; Expand-Archive "$d\swiftui-ui-patterns.zip" -DestinationPath $d -Force; ri "$d\swiftui-ui-patterns.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して swiftui-ui-patterns.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → swiftui-ui-patterns フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-17
取得日時
2026-05-17
同梱ファイル
31

💬 こう話しかけるだけ — サンプルプロンプト

  • Swiftui UI Patterns を使って、最小構成のサンプルコードを示して
  • Swiftui UI Patterns の主な使い方と注意点を教えて
  • Swiftui UI Patterns を既存プロジェクトに組み込む方法を教えて

これをClaude Code に貼るだけで、このSkillが自動発動します。

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

SwiftUI UI パターン

クイックスタート

使用する場面

  • SwiftUIの画面、フロー、または再利用可能なUIコンポーネントを作成またはリファクタリングする際。
  • ナビゲーション、シート、非同期状態、プレビュー、またはコンポーネントパターンに関するガイダンスが必要な場合。

目標に基づいてトラックを選択してください。

既存のプロジェクト

  • 機能または画面と、主要なインタラクションモデル(リスト、詳細、エディター、設定、タブ付き)を特定します。
  • rg "TabView\("などを使ってリポジトリ内の近くの例を見つけ、最も近いSwiftUIビューを読みます。
  • ローカルの慣例を適用します。SwiftUIネイティブの状態を優先し、可能な限り状態をローカルに保ち、共有される依存関係には環境インジェクションを使用します。
  • references/components-index.mdから関連するコンポーネントリファレンスを選択し、そのガイダンスに従います。
  • プライマリコンテンツをドラッグまたはスクロールしてセカンダリコンテンツを表示するインタラクションの場合、ジェスチャーを手動で実装する前にreferences/scroll-reveal.mdを読みます。
  • 小さく、焦点を絞ったサブビューとSwiftUIネイティブのデータフローでビューを構築します。

新規プロジェクトの足場固め

  • references/app-wiring.mdから始めて、TabView + NavigationStack + シートを配線します。
  • 提供されたスケルトンに基づいて、最小限の AppTabRouterPath を追加します。
  • 最初に必要なUI(TabView、NavigationStack、Sheets)に基づいて、次のコンポーネントリファレンスを選択します。
  • 新しい画面が追加されるにつれて、ルートとシートのenumを拡張します。

従うべき一般的なルール

  • 最新のSwiftUI状態(@State@Binding@Observable@Environment)を使用し、不要なビューモデルは避けます。
  • デプロイターゲットにiOS 16以前が含まれており、iOS 17で導入されたObservation APIを使用できない場合は、ルートの所有権には@StateObject、注入された監視には@ObservedObject、真に共有されるアプリレベルの状態にのみ@EnvironmentObjectを使用するObservableObjectにフォールバックします。
  • コンポジションを優先し、ビューを小さく、焦点を絞ったものに保ちます。
  • .taskと明示的なローディング/エラー状態を持つasync/awaitを使用します。再起動、キャンセル、デバウンスのガイダンスについては、references/async-state.mdを読みます。
  • 共有されるアプリサービスは@Environmentに保持しますが、機能ローカルの依存関係やモデルには明示的なイニシャライザインジェクションを優先します。ルートの配線パターンについては、references/app-wiring.mdを読みます。
  • デプロイターゲットに適合する最新のSwiftUI APIを優先し、パターンが依存するたびに最小OSを明記します。
  • レガシーファイルを編集する場合にのみ、既存のレガシーパターンを維持します。
  • プロジェクトのフォーマッターとスタイルガイドに従います。
  • シート: 状態が選択されたモデルを表す場合は、.sheet(isPresented:)よりも.sheet(item:)を優先します。シートのボディ内でif letを使用することは避けます。シートは自身のアクションを所有し、onCancel/onConfirmクロージャを転送する代わりに、内部でdismiss()を呼び出すべきです。
  • スクロール駆動の表示: スクロールオフセットから正規化された進行値を導出し、その単一の真実の源から視覚状態を駆動することを優先します。スクロールだけではインタラクションを表現できない場合を除き、並列のジェスチャー状態マシンは避けます。

状態の所有権の概要

所有権モデルに合致する最も狭い状態ツールを使用します。

シナリオ 推奨パターン
1つのビューが所有するローカルUI状態 @State
子が親が所有する値の状態を変更する @Binding
iOS 17以降のルートが所有する参照モデル @Observable型を持つ@State
iOS 17以降で子が注入された@Observableモデルを読み取るまたは変更する 格納されたプロパティとして明示的に渡す
共有されるアプリサービスまたは設定 @Environment(Type.self)
iOS 16以前のレガシー参照モデル ルートで@StateObject、注入時に@ObservedObject

まず所有権の場所を選択し、次にラッパーを選択します。単純な値の状態で十分な場合は、参照モデルを導入しないでください。

横断的な参照

  • references/navigationstack.md: ナビゲーションの所有権、タブごとの履歴、およびenumルーティング。
  • references/sheets.md: 一元化されたモーダルプレゼンテーションとenum駆動のシート。
  • references/deeplinks.md: URL処理と外部リンクをアプリの目的地にルーティングする方法。
  • references/app-wiring.md: ルートの依存関係グラフ、環境の使用法、およびアプリシェルの配線。
  • references/async-state.md: .task.task(id:)、キャンセル、デバウンス、および非同期UI状態。
  • references/previews.md: #Preview、フィクスチャ、モック環境、および分離されたプレビュー設定。
  • references/performance.md: 安定したID、監視スコープ、遅延コンテナ、およびレンダリングコストのガードレール。

アンチパターン

  • レイアウト、ビジネスロジック、ネットワーキング、ルーティング、フォーマットを1つのファイルに混在させた巨大なビュー。
  • 相互に排他的なシート、アラート、またはナビゲーションの目的地のための複数のブールフラグ。
  • ビューのライフサイクルフックや注入されたモデル/サービスではなく、body駆動のコードパス内で直接ライブサービス呼び出しを行うこと。
  • より良いコンポジションで解決すべき型ミスマッチを回避するためにAnyViewに手を伸ばすこと。
  • 明確な所有権の理由なしに、すべての共有依存関係を@EnvironmentObjectまたはグローバルルーターにデフォルト設定すること。

新しいSwiftUIビューのワークフロー

  1. UIコードを記述する前に、ビューの状態、所有権の場所、および最小OSの仮定を定義します。
  2. @Environmentに属する依存関係と、明示的なイニシャライザ入力として残すべき依存関係を特定します。
  3. ビュー階層、ルーティングモデル、およびプレゼンテーションポイントをスケッチし、繰り返される部分をサブビューに抽出します。複雑なナビゲーションについては、references/navigationstack.mdreferences/sheets.md、またはreferences/deeplinks.mdを読みます。続行する前に、コンパイラエラーがないことをビルドして確認してください。
  4. .taskまたは.task(id:)、および必要に応じて明示的なローディング状態とエラー状態を使用して非同期ローディングを実装します。作業が入力の変更やキャンセルに依存する場合は、references/async-state.mdを読みます。
  5. プライマリ状態とセカンダリ状態のプレビューを追加し、UIがインタラクティブな場合はアクセシビリティラベルまたは識別子を追加します。ビューにフィクスチャまたは注入されたモック依存関係が必要な場合は、references/previews.mdを読みます。
  6. ビルドで検証します。コンパイラエラーがないことを確認し、プレビューがクラッシュせずにレンダリングされることを確認し、状態の変更が伝播することを確認します。
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

SwiftUI UI Patterns

Quick start

When to Use

  • When creating or refactoring SwiftUI screens, flows, or reusable UI components.
  • When you need guidance on navigation, sheets, async state, previews, or component patterns.

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

  • 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 error states when needed. Read references/async-state.md when the work depends on changing inputs or cancellation.
  5. Add previews for the primary and secondary states, then add accessibility labels or identifiers when the UI is interactive. Read references/previews.md when the view needs fixtures or injected mock dependencies.
  6. Validate with a build: confirm no compiler errors, check that previews render without crashing, ensure state changes propagate correctly, and sanity-check that list identity and observation scope will not cause avoidable re-renders. Read references/performance.md if the screen is large, scroll-heavy, or frequently updated. For common SwiftUI compilation errors — missing @State annotations, ambiguous ViewBuilder closures, or mismatched generic types — resolve them before updating callsites. If the build fails: read the error message carefully, fix the identified issue, then rebuild before proceeding to the next step. If a preview crashes, isolate the offending subview, confirm its state initialisation is valid, and re-run the preview before continuing.

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 local conventions.
  • Pitfalls and performance notes.
  • Paths to existing examples in the current repo.

Adding a new component reference

  • Create references/<component>.md.
  • Keep it short and actionable; link to concrete files in the current repo.
  • Update references/components-index.md with the new entry.

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.

同梱ファイル

※ ZIPに含まれるファイル一覧。`SKILL.md` 本体に加え、参考資料・サンプル・スクリプトが入っている場合があります。