重构并审查 SwiftUI 视图文件以实现一致的结构、依赖项注入和观察使用。当被要求清理 SwiftUI 视图的布局/排序、安全地处理视图模型(如果可能的话,非可选)或标准化依赖项和 @Observable 状态的初始化和初始化方式时使用
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install swiftui-view-refactor或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install swiftui-view-refactor⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/swiftui-view-refactor/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- 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. ---
_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.安装 Swiftui 视图重构 后,可以对 AI 说这些话来触发它
Help me get started with Swiftui View Refactor
Explains what Swiftui View Refactor does, walks through the setup, and runs a quick demo based on your current project
Use Swiftui View Refactor to refactor and review SwiftUI view files for consistent structure, de...
Invokes Swiftui View Refactor with the right parameters and returns the result directly in the conversation
What can I do with Swiftui View Refactor in my developer & devops workflow?
Lists the top use cases for Swiftui View Refactor, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/swiftui-view-refactor/ 目录(个人级,所有项目可用),或 .claude/skills/swiftui-view-refactor/(项目级)。重启 AI 客户端后,用 /swiftui-view-refactor 主动调用,或让 AI 根据上下文自动发现并使用。
Swiftui 视图重构 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
Swiftui 视图重构 可免费安装使用。请查阅仓库了解许可证信息。
重构并审查 SwiftUI 视图文件以实现一致的结构、依赖项注入和观察使用。当被要求清理 SwiftUI 视图的布局/排序、安全地处理视图模型(如果可能的话,非可选)或标准化依赖项和 @Observable 状态的初始化和初始化方式时使用
Swiftui 视图重构 属于「Developer & DevOps」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。
Automate my developer & devops tasks using Swiftui View Refactor
Identifies repetitive steps in your workflow and sets up Swiftui View Refactor to handle them automatically