# Refactor SwiftUI Views Safely

SwiftUI views can become hard to read when state, dependencies, and helper views drift into inconsistent order. This skill guides Claude, Codex, and Claude Code to refactor views with MV-first structure and Observation-aware state.

## Install

```bash
npx skillstore add dimillian/swiftui-view-refactor
```

## Metadata

- Status: approved
- Slug: dimillian-swiftui-view-refactor
- Skillstore revision: r1
- Version status: missing
- Tree hash: 249fff205684cb743504816b93066fabddd47dbd2cce813192b3f1706af6e334
- Author: Dimillian
- GitHub username: Dimillian
- License: MIT
- Repository: https://github.com/Dimillian/Skills/tree/main/swiftui-view-refactor
- Ref: 72d5025b022c77f7a51bdf5c1637c689c80e89d1
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: network, external\_commands
- Quality score: 74
- Public page: https://skillstore.pages.dev/skills/dimillian-swiftui-view-refactor
- Manifest: https://skillstore.pages.dev/api/skills/dimillian-swiftui-view-refactor/manifest

## Capabilities

- Reorders SwiftUI view members into a consistent top-to-bottom structure.
- Splits large view bodies into computed views or small subviews when appropriate.
- Applies MV-first guidance using state, environment, queries, tasks, and change handlers.
- Keeps existing view models non-optional when dependencies can initialize them safely.
- Reviews Observation usage for root observable objects and explicit state passing.
- Groups large-file helpers with private extensions and clear section markers.

## Use Cases

- Clean Up a Growing View: Reorganize a long SwiftUI view without changing layout, state flow, or user-visible behavior.
- Standardize Team Conventions: Apply one member order and dependency pattern across files during code review.
- Modernize Observation Usage: Review existing observable view models and convert avoidable optional state into explicit initialization.

## Prompt Templates

### Review One View

```
Review this SwiftUI view for ordering, state placement, and helper structure. Suggest a behavior-preserving refactor first.
```

### Refactor Without Behavior Changes

```
Refactor this SwiftUI file using the skill guidelines. Keep layout, data flow, names, and behavior unchanged unless a change is required.
```

### Evaluate View Model Need

```
Decide whether this view needs a view model. Prefer MV patterns, and explain any case where the existing view model should remain.
```

### Modernize a Large Feature View

```
Refactor this large SwiftUI feature view into clear sections, private helpers, and explicit dependencies. Preserve behavior and summarize each structural change.
```

## Limitations

- Does not run or compile the Swift project by itself.
- Does not infer hidden product requirements beyond supplied SwiftUI files.
- Does not replace architecture decisions that require team consensus.
- May need project-specific naming conventions or design-system rules.

## Best Practices

- Provide the complete view file and mention any behavior that must not change.
- Ask for a short change summary after refactoring.
- Run project tests and previews after applying structural changes.

## Anti Patterns

- Using the skill to introduce view models when the existing SwiftUI view does not need one.
- Requesting visual redesigns while also asking for behavior-preserving refactors.
- Providing isolated snippets without dependencies, environment values, or related model types.

## Security Audit

- Audited at: 2026-07-06T12:24:30.633\+00:00
- Summary: All static detections appear to be false positives caused by Markdown inline code, Swift fenced examples, and SwiftData terminology. I found no evidence of executable shell commands, network access, system reconnaissance, prompt injection, or data exfiltration intent in SKILL.md or references/mv-patterns.md.

## Stats

- Views: 308
- Downloads: 10
- Favorites: 0
- Popularity score: 0
