← 返回 Skills 市场
steipete

Swiftui View Refactor

作者 Peter Steinberger · GitHub ↗ · v1.0.0
cross-platform ✓ 安全检测通过
2794
总下载
6
收藏
8
当前安装
1
版本数
在 OpenClaw 中安装
/install swiftui-view-refactor
功能描述
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.
使用说明 (SKILL.md)

SwiftUI View Refactor

Attribution: copied from @Dimillian’s Dimillian/Skills (2025-12-31).

Overview

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.

Core Guidelines

1) View ordering (top → bottom)

  • Environment
  • private/public let
  • @State / other stored properties
  • computed var (non-view)
  • init
  • body
  • computed view builders / other view helpers
  • helper / async functions

2) Prefer MV (Model-View) patterns

  • Default to MV: Views are lightweight state expressions; models/services own business logic.
  • Favor @State, @Environment, @Query, and task/onChange for orchestration.
  • Inject services and shared models via @Environment; keep views small and composable.
  • Split large views into subviews rather than introducing a view model.

3) Split large bodies and view properties

  • If body grows beyond a screen or has multiple logical sections, split it into smaller subviews.
  • Extract large computed view properties (var header: some View { ... }) into dedicated View types when they carry state or complex branching.
  • It's fine to keep related subviews as computed view properties in the same file; extract to a standalone View struct only when it structurally makes sense or when reuse is intended.
  • Prefer passing small inputs (data, bindings, callbacks) over reusing the entire parent view state.

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)
        }
    }
}

4) View model handling (only if already present)

  • Do not introduce a view model unless the request or existing code clearly calls for one.
  • If a view model exists, make it non-optional when possible.
  • Pass dependencies to the view via init, then pass them into the view model in the view's init.
  • Avoid bootstrapIfNeeded patterns.

Example (Observation-based):

@State private var viewModel: SomeViewModel

init(dependency: Dependency) {
    _viewModel = State(initialValue: SomeViewModel(dependency: dependency))
}

5) Observation usage

  • For @Observable reference types, store them as @State in the root view.
  • Pass observables down explicitly as needed; avoid optional state unless required.

Workflow

  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.

Notes

  • Prefer small, explicit helpers over large conditional blocks.
  • Keep computed view builders below body and non-view computed vars above init.
  • For MV-first guidance and rationale, see references/mv-patterns.md.
安全使用建议
This skill appears coherent and low-risk: it only provides refactor rules for SwiftUI code and asks for no credentials or installs. Before applying automated refactors, review diffs or run them in a branch/PR to confirm behavior is unchanged. Don’t include secrets or private credentials in code you paste to any skill. If you’re concerned about an unknown source, prefer manual review or only use the guidelines as a checklist rather than allowing automated edits. If you want to prevent autonomous runs, restrict the skill’s invocation in your agent settings (it is user-invocable and can be allowed/disallowed at install time).
功能分析
Type: OpenClaw Skill Name: swiftui-view-refactor Version: 1.0.0 The skill bundle is benign. All files, including the `SKILL.md` instructions for the AI agent, are entirely focused on providing architectural and refactoring guidelines for SwiftUI views. There is no evidence of data exfiltration, malicious execution, persistence, obfuscation, or prompt injection attempts designed to subvert the agent's behavior or access sensitive data. The content is consistent with its stated purpose of assisting with SwiftUI code review and refactoring.
能力评估
Purpose & Capability
The skill's name/description (SwiftUI view refactor) matches the SKILL.md content: style and refactor guidelines for SwiftUI views. It requests no binaries, env vars, or installs that would be unrelated to refactoring Swift source.
Instruction Scope
SKILL.md contains only coding guidelines, examples, and a workflow for refactoring SwiftUI views. It does not instruct the agent to read system files, access credentials, or transmit code to external endpoints. Note: as an instruction-only skill, actual file access depends on what the agent is given at invocation — the skill itself doesn't expand scope.
Install Mechanism
No install spec or code files are included. Nothing is written to disk or downloaded by the skill.
Credentials
The skill declares no required environment variables, credentials, or config paths — proportional to a rules-and-style refactor helper.
Persistence & Privilege
always is false and the skill has no install or persistence steps. disable-model-invocation is false (normal platform default) but there are no other elevated privileges or cross-skill configuration changes requested.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install swiftui-view-refactor
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /swiftui-view-refactor 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
元数据
Slug swiftui-view-refactor
版本 1.0.0
许可证
累计安装 8
当前安装数 8
历史版本数 1
常见问题

Swiftui View Refactor 是什么?

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. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 2794 次。

如何安装 Swiftui View Refactor?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install swiftui-view-refactor」即可一键安装,无需额外配置。

Swiftui View Refactor 是免费的吗?

是的,Swiftui View Refactor 完全免费(开源免费),可自由下载、安装和使用。

Swiftui View Refactor 支持哪些平台?

Swiftui View Refactor 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Swiftui View Refactor?

由 Peter Steinberger(@steipete)开发并维护,当前版本 v1.0.0。

💬 留言讨论