From sundial-org-awesome-openclaw-skills-4
Refactors SwiftUI views for consistent structure, dependency injection, and Observation usage. Helps clean up view layout, handle view models safely, and standardize state initialization.
How this skill is triggered — by the user, by Claude, or both
Slash command
/sundial-org-awesome-openclaw-skills-4:swiftui-view-refactorThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
_Attribution: copied from @Dimillian’s `Dimillian/Skills` (2025-12-31)._
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.@State, @Environment, @Query, task, and onChange.@State view model initialized in init by passing dependencies from the view.@State for root @Observable view models, no redundant wrappers.body and non-view computed vars above init.references/mv-patterns.md.npx claudepluginhub joshuarweaver/cascade-ai-ml-agents-misc-2 --plugin sundial-org-awesome-openclaw-skills-4Refactors SwiftUI view files toward small subviews, MV-first data flow, stable view trees, explicit dependencies, extracted actions, and correct Observable usage.
Refactors large SwiftUI views into small, explicit subview types with stable data flow. Splits long body implementations, enforces MV pattern, and prefers dedicated View types over computed helpers.
Builds and reviews SwiftUI views with modern MV architecture, state management, composition, and isolated previews. Use for structuring SwiftUI state, managing @Observable, composing views, or correcting SwiftUI patterns.