Peter Steinberger

Swiftui View Refactor

開発v1.0.0
作者:Peter Steinberger更新日 2026-05-11swiftui-view-refactor@clawhub_steipete/swiftui-view-refactor
コード生成コードレビュー

AlphaMoatによると、2026-09時点でSwiftui View Refactorのダウンロード数は3,953、スター数は6で、AIスキル全体5,078件中2,610位、開発では577件中340位です。

インストール数
129
ダウンロード数
3953
スター数
6
総合順位
#2,610
全体の上位 52% · 開発の上位 59%
プラットフォームインストール数ダウンロード数スター数コメント
ClawHub ↗12839286-
SkillHub ↗12939536—

プラットフォームごとに集計方法と集計時点が異なります。

このスキルでできること

ビューのプロパティやメソッドの順序を整え、軽量なMV構成を推奨し、依存性注入とObservation状態の扱いを示します。推奨する設計がすべてのコードベースに合うとは限りません。適用前にプロジェクトの慣習と照らし合わせ、変更差分を確認し、機械的なリファクタリングでレイアウト、挙動、業務ロジックが変わらないようにしてください。

資料公開日 2026-10-29

できること

  • SwiftUIビューファイルの構成を統一する
  • 依存性注入や状態の流れを確認する
  • プロジェクトの慣習に合う場合にビューコードを整理する

使う場面

  • 利用者がSwiftUIビューのレビューや整理を依頼したとき
  • 対象プロジェクトで推奨するMV構成を採用できるとき
  • 変更を確認し、通常の検証を実行できるとき

プロンプト例

スキルのドキュメントをもとに生成した例であり、実際の実行結果ではありません。

このSwiftUIビューをプロジェクトの慣習に照らしてレビューし、まず構成変更案を示してください。レイアウト、挙動、業務ロジックを保ち、編集は私の承認を待ってください。

月次の推移

ダウンロード数3953
2606333040532026-03 · ダウンロード数 27062026-05 · ダウンロード数 32362026-06 · ダウンロード数 33932026-07 · ダウンロード数 36582026-08 · ダウンロード数 37952026-09 · ダウンロード数 395326-0326-09
スター数6
5672026-03 · スター数 62026-05 · スター数 62026-06 · スター数 62026-07 · スター数 62026-08 · スター数 62026-09 · スター数 626-0326-09

2026-09 から集計方法を変更し、同名スキルを作者ごとに分けて集計し、全スキルを対象にしました。破線は変更前の月で、変更後のデータとは直接比較せず、変更をまたぐ増減も計算していません。

月ダウンロード数前月比スター数
2026-093953—6
2026-083795+3.7%6
2026-073658+7.8%6
2026-063393+4.9%6
2026-053236—6
2026-032706—6

SKILL.md 原文

作者が公開した元のファイルをテキストのまま表示しています。AlphaMoat による編集や審査はしていません。リンクはクリックできません。コマンドは内容を確認してから実行してください。取得日 2026-10-23。

4.7 KB・ClawHub v1.0.0
---
name: swiftui-view-refactor
description: Refactor and review SwiftUI view files for consistent structure, dependency injection, and Observation usage. Use when asked to clean up a SwiftUI view’s layout/ordering, handle view models safely (non-optional when possible), or standardize how dependencies and @Observable state are initialized and passed.
---

# SwiftUI View Refactor

_Attribution: copied from @Dimillian’s `Dimillian/Skills` (2025-12-31)._

## Overview
すべて表示(全 135 行)
Apply a consistent structure and dependency pattern to SwiftUI views, with a focus on ordering, Model-View (MV) patterns, careful view model handling, and correct Observation usage.

## Core Guidelines

### 1) View ordering (top → bottom)
- Environment
- `private`/`public` `let`
- `@State` / other stored properties
- computed `var` (non-view)
- `init`
- `body`
- computed view builders / other view helpers
- helper / async functions

### 2) Prefer MV (Model-View) patterns
- Default to MV: Views are lightweight state expressions; models/services own business logic.
- Favor `@State`, `@Environment`, `@Query`, and `task`/`onChange` for orchestration.
- Inject services and shared models via `@Environment`; keep views small and composable.
- Split large views into subviews rather than introducing a view model.

### 3) Split large bodies and view properties
- If `body` grows beyond a screen or has multiple logical sections, split it into smaller subviews.
- Extract large computed view properties (`var header: some View { ... }`) into dedicated `View` types when they carry state or complex branching.
- It's fine to keep related subviews as computed view properties in the same file; extract to a standalone `View` struct only when it structurally makes sense or when reuse is intended.
- Prefer passing small inputs (data, bindings, callbacks) over reusing the entire parent view state.

Example (extracting a section):

```swift
var body: some View {
    VStack(alignment: .leading, spacing: 16) {
        HeaderSection(title: title, isPinned: isPinned)
        DetailsSection(details: details)
        ActionsSection(onSave: onSave, onCancel: onCancel)
    }
}
```

Example (long body → shorter body + computed views in the same file):

```swift
var body: some View {
    List {
        header
        filters
        results
        footer
    }
}

private var header: some View {
    VStack(alignment: .leading, spacing: 6) {
        Text(title).font(.title2)
        Text(subtitle).font(.subheadline)
    }
}

private var filters: some View {
    ScrollView(.horizontal, showsIndicators: false) {
        HStack {
            ForEach(filterOptions, id: \.self) { option in
                FilterChip(option: option, isSelected: option == selectedFilter)
                    .onTapGesture { selectedFilter = option }
            }
        }
    }
}
```

Example (extracting a complex computed view):

```swift
private var header: some View {
    HeaderSection(title: title, subtitle: subtitle, status: status)
}

private struct HeaderSection: View {
    let title: String
    let subtitle: String?
    let status: Status

    var body: some View {
        VStack(alignment: .leading, spacing: 4) {
            Text(title).font(.headline)
            if let subtitle { Text(subtitle).font(.subheadline) }
            StatusBadge(status: status)
        }
    }
}
```

### 4) View model handling (only if already present)
- Do not introduce a view model unless the request or existing code clearly calls for one.
- If a view model exists, make it non-optional when possible.
- Pass dependencies to the view via `init`, then pass them into the view model in the view's `init`.
- Avoid `bootstrapIfNeeded` patterns.

Example (Observation-based):

```swift
@State private var viewModel: SomeViewModel

init(dependency: Dependency) {
    _viewModel = State(initialValue: SomeViewModel(dependency: dependency))
}
```

### 5) Observation usage
- For `@Observable` reference types, store them as `@State` in the root view.
- Pass observables down explicitly as needed; avoid optional state unless required.

## Workflow

1) Reorder the view to match the ordering rules.
2) Favor MV: move lightweight orchestration into the view using `@State`, `@Environment`, `@Query`, `task`, and `onChange`.
3) If a view model exists, replace optional view models with a non-optional `@State` view model initialized in `init` by passing dependencies from the view.
4) Confirm Observation usage: `@State` for root `@Observable` view models, no redundant wrappers.
5) Keep behavior intact: do not change layout or business logic unless requested.

## Notes

- Prefer small, explicit helpers over large conditional blocks.
- Keep computed view builders below `body` and non-view computed vars above `init`.
- For MV-first guidance and rationale, see `references/mv-patterns.md`.

開発の人気スキル

Peter Steinbergerのその他のスキル

データ月:2026-09 · ダウンロード数、スター数、インストール数は公開スキルレジストリ(ClawHub、SkillHub)から月単位で集計しています。詳しくはデータの方法論をご覧ください。