本文へスキップ
Skillpedia
WebサイトとUI(フロントエンド)48k · #5914

swiftui-ui-patterns

できること

このガイドは、SwiftUIで作られたアプリのコードを整理する方法を解説します。画面間の移動(ナビゲーション)の管理、追加のウインドウ(シート)の表示、読み込みに時間がかかる処理の扱い方、再利用可能な画面パーツの作り方を紹介します。

使う場面

  • ✓SwiftUIアプリの新しい画面やパーツを作るとき。
  • ✓ユーザーが画面間を移動する仕組みを整理したいとき。
  • ✓複数の場所で使えるインターフェースの部品を作りたいとき。

スキルのリンク

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/swiftui-ui-patterns/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/swiftui-ui-patterns/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“SwiftUIで画面間のナビゲーションを整理するにはどうすればよいですか?”

毎週5つの新しいスキル。1分で読めます。

仕組み

このガイドでは、@Stateや@Bindingなど、SwiftUIの整理用の仕組みを使うための例とルールを示します。また、保守や読みやすさを高めるためのコードの構成方法を提案します。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

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.

Example prerequisites

The references contain application sketches, not a complete app. Supply the named project views, models, adapters and theme tokens; verify imports, actual error contracts and minimum OS with the installed SDK before adapting them. Bind every visible action to a real tested handler, make persistence failures observable and use inert preview data. A successful code example is not evidence of a tested screen or deployed service.

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.

…

よくある質問

「シート」とは何ですか?

今の画面の上に表示される小さなウインドウのことです。フォームへの入力や詳細の表示など、今の画面を離れずに行える簡単な作業に使われます。

「非同期の状態(async state)」とは何を意味しますか?

インターネットからのデータ取得のように、完了までに時間がかかる処理を扱う方法のことです。読み込み中の表示や、起こりうるエラーへの対応も含みます。

古いプロジェクトでも使えますか?

はい。このガイドでは古いSwiftUIのバージョン向けの代替方法も紹介していますが、可能であれば最新のツールを使うことをおすすめしています。

詳細

作者による元の説明

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

repo: sickn33/agentic-awesome-skills

人気

GitHubのスター
48k
ランキング
#5914
ライセンス
MIT
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル