Loading...
Loading...
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.
npx skill4agent add kmshdev/claude-swift-toolkit swiftui-view-refactorgrep -rl "var body.*some View" --include="*.swift" . 2>/dev/null | head -20 || echo "none found"swiftui-ui-patternscode-analyzerprivatepubliclet@Statevarinitbody@State@Environment@QuerytaskonChange@Environmentbodyvar header: some View { ... }ViewViewvar body: some View {
VStack(alignment: .leading, spacing: 16) {
HeaderSection(title: title, isPinned: isPinned)
DetailsSection(details: details)
ActionsSection(onSave: onSave, onCancel: onCancel)
}
}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 }
}
}
}
}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)
}
}
}bodyif/elseoverlayopacitydisabledtoolbarvar body: some View {
List {
documentsListContent
}
.toolbar {
if canEdit {
editToolbar
}
}
}var documentsListView: some View {
if canEdit {
editableDocumentsList
} else {
readOnlyDocumentsList
}
}initinitbootstrapIfNeeded@State private var viewModel: SomeViewModel
init(dependency: Dependency) {
_viewModel = State(initialValue: SomeViewModel(dependency: dependency))
}@Observable@State@State@Environment@QuerytaskonChangeif@Stateinit@State@Observablebodyinitreferences/mv-patterns.mdprivate// MARK: -// MARK: - Actions// MARK: - Subviews// MARK: - Helpersstructbody