Peter Steinberger

Swiftui View Refactor

Developmentv1.0.0
By Peter SteinbergerUpdated 2026-05-11swiftui-view-refactor@clawhub_steipete/swiftui-view-refactor
Code GenerationCode Review

According to AlphaMoat, as of 2026-09, Swiftui View Refactor has 3,953 downloads and 6 stars — ranked #2,610 of 5,078 AI skills overall, and #340 of 577 in Development.

Installs
129
Downloads
4.0K
Stars
6
Overall Rank
#2,610
Top 52% overall · Top 59% in Development
PlatformInstallsDownloadsStarsComments
ClawHub ↗1283.9K6-
SkillHub ↗1294.0K6—

Platforms count differently and update at different times.

What this skill does

The guidance standardizes the ordering of view properties and methods, favors lightweight views organized around MV, and addresses dependency injection and Observation state. Its architectural preference may not fit every codebase. Check it against local conventions, review each proposed diff, and ensure a mechanical refactor does not change layout, behavior, or business logic.

Profile published 2026-10-29

What you can do with it

  • Standardize the organization of SwiftUI view files
  • Review dependency injection and state flow
  • Refactor view code when it matches project conventions

When to use it

  • The user asks to review or clean up a SwiftUI view
  • The project can adopt the preferred MV structure
  • Changes can be reviewed and checked with the project’s normal validation

Example prompts

Generated from the skill’s documentation as examples; not results of actual runs.

Review this SwiftUI view against the project’s conventions and first show the proposed structural changes. Preserve layout, behavior, and business logic; wait for my approval before editing.

Monthly Trend

Downloads4.0K
2.6K3.3K4.1K2026-03 · Downloads 2.7K2026-05 · Downloads 3.2K2026-06 · Downloads 3.4K2026-07 · Downloads 3.7K2026-08 · Downloads 3.8K2026-09 · Downloads 4.0K26-0326-09
Stars6
5672026-03 · Stars 62026-05 · Stars 62026-06 · Stars 62026-07 · Stars 62026-08 · Stars 62026-09 · Stars 626-0326-09

The counting method changed in 2026-09: skills with the same name are now counted separately by author, and the full catalog is covered. Dashed lines show months before the change; they are not compared with later months, and no growth is computed across the change.

MonthDownloadsMoMStars
2026-094.0K—6
2026-083.8K+3.7%6
2026-073.7K+7.8%6
2026-063.4K+4.9%6
2026-053.2K—6
2026-032.7K—6

SKILL.md (original)

The author’s original file, shown as plain text without edits or review by AlphaMoat. Links are not clickable; check commands before running them. Fetched 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
Show all (135 lines)
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`.

Popular in Development

More from Peter Steinberger

Data month: 2026-09 · Downloads, stars and installs are aggregated monthly from public skill registries (ClawHub, SkillHub). See methodology.