swiftui-view-refactorRefactor 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.
Install via ClawdBot CLI:
clawdbot install steipete/swiftui-view-refactor_Attribution: copied from @Dimillian’s Dimillian/Skills (2025-12-31)._
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.
private/public let@State / other stored propertiesvar (non-view)initbody@State, @Environment, @Query, and task/onChange for orchestration.@Environment; keep views small and composable.body grows beyond a screen or has multiple logical sections, split it into smaller subviews.var header: some View { ... }) into dedicated View types when they carry state or complex branching.View struct only when it structurally makes sense or when reuse is intended.Example (extracting a section):
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):
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):
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)
}
}
}
init, then pass them into the view model in the view's init.bootstrapIfNeeded patterns.Example (Observation-based):
@State private var viewModel: SomeViewModel
init(dependency: Dependency) {
_viewModel = State(initialValue: SomeViewModel(dependency: dependency))
}
@Observable reference types, store them as @State in the root view.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.
body and non-view computed vars above init.references/mv-patterns.md.Generated Mar 1, 2026
Agency developers refactoring legacy SwiftUI views from client projects to enforce consistent structure and improve maintainability. They use this skill to standardize code across multiple apps, ensuring clean dependency injection and Observation patterns for easier onboarding and updates.
A solo developer cleaning up personal or client SwiftUI projects to reduce technical debt and enhance performance. They apply the skill to reorder view properties, split large bodies into subviews, and handle view models safely for more reliable and scalable code.
A large company's mobile team refactoring SwiftUI views in a production app to adopt MV patterns and consistent ordering. They use this skill to streamline collaboration, reduce bugs from optional view models, and integrate with shared services via Environment for better testing.
A startup developing an educational iOS app uses this skill to refactor SwiftUI views for clarity and efficiency. They focus on splitting complex views into subviews and using Observation correctly to handle dynamic content and user interactions without performance issues.
Offer this refactoring skill as part of a premium IDE plugin or code assistant service. Developers pay a monthly fee to access automated SwiftUI refactoring, reducing manual work and improving code quality in their projects.
Provide expert consulting and training sessions to companies adopting SwiftUI. Use this skill to demonstrate best practices, refactor existing codebases, and train teams on MV patterns and Observation usage for faster development cycles.
Integrate this skill into an open-source tool or library for SwiftUI development. Monetize through sponsorships, donations, or premium support tiers, helping developers adopt consistent refactoring practices at scale.
💬 Integration Tip
Integrate this skill into CI/CD pipelines to automatically enforce SwiftUI view structure during code reviews, ensuring consistency across team contributions without manual oversight.
Full Windows desktop control. Mouse, keyboard, screenshots - interact with any Windows application like a human.
Control Android devices via ADB with support for UI layout analysis (uiautomator) and visual feedback (screencap). Use when you need to interact with Android apps, perform UI automation, take screenshots, or run complex ADB command sequences.
Build, test, and ship iOS apps with Swift, Xcode, and App Store best practices.
Control macOS GUI apps visually — take screenshots, click, scroll, type. Use when the user asks to interact with any Mac desktop application's graphical interface.
Best practices and example-driven guidance for building SwiftUI views and components. Use when creating or refactoring SwiftUI UI, designing tab architecture with TabView, composing screens, or needing component-specific patterns and examples.
Write safe Swift code avoiding memory leaks, optional traps, and concurrency bugs.