Communitygithub.com

ComeOnOliver/skillshub

重構與審查 SwiftUI 視圖檔案,使其具備一致的結構、依賴注入與 Observation 使用方式。當要求整理 SwiftUI 視圖的佈局/順序、安全處理視圖模型(盡可能非可選)、或標準化依賴與 @Observable 狀態的初始化及傳遞時使用。

skillshub 是什麼?

這是一個專為 SwiftUI 開發者設計的 AI 助手技能,旨在自動化重構與審查視圖檔案的流程。其核心目標是強制執行一致的程式碼結構,包含視圖屬性的頂層排序(從環境變數、屬性到 body 與輔助函式)、優先採用輕量級的 Model-View(MV)模式(而非引入專用視圖模型),並確保正確使用 Observation 框架。技能會將大型 body 拆分為較小的子視圖或計算屬性,同時在需要時安全地處理已存在的視圖模型(例如使其非可選化,並在 init 中注入依賴)。此技能支援 Claude Code、Coder、Copilot 等基於命令列的 AI 代理平台,能從 SKILL.md 文件讀取規則,並在開發者要求「清理 SwiftUI 視圖」時自動套用結構化的工作流程。它會保留原有的佈局與業務邏輯,僅專注於程式碼組織與模式一致性。

相容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ComeOnOliver/skillshub/tree/HEAD/skills/aiskillstore/marketplace/dimillian/swiftui-view-refactor

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

SwiftUI 視圖重構

概述

為 SwiftUI 視圖套用一致的結構與依賴模式,重點關注順序、Model-View(MV)模式、謹慎的視圖模型處理以及正確的 Observation 使用方式。

核心準則

1) 視圖順序(從上到下)

  • Environment
  • private/public let
  • @State / 其他儲存屬性
  • 計算屬性 var(非視圖)
  • init
  • body
  • 計算視圖建構器 / 其他視圖輔助功能
  • 輔助 / 非同步函式

2) 優先採用 MV(Model-View)模式

  • 預設 MV:視圖是輕量級的狀態表達;模型/服務擁有業務邏輯。
  • 偏好使用 @State、@Environment、@Query 以及 task/onChange 進行編排。
  • 透過 @Environment 注入服務與共享模型;保持視圖小巧且可組合。
  • 將大型視圖拆分成子視圖,而不是引入視圖模型。

3) 拆分大型 body 與視圖屬性

  • 如果 body 超過一個畫面或包含多個邏輯區段,將其拆分為較小的子視圖。
  • 當大型計算視圖屬性(var header: some View { ... })帶有狀態或複雜分支時,將其提取為專用的 View 類型。
  • 可以在同一個檔案中將相關的子視圖保留為計算視圖屬性;僅在結構上合理或有意重複使用時,才提取為獨立的 View 結構。
  • 偏好傳遞小型輸入(資料、綁定、回呼),而非重複使用整個父視圖狀態。

範例(提取區段):

var body: some View {
    VStack(alignment: .leading, spacing: 16) {
        HeaderSection(title: title, isPinned: isPinned)
        DetailsSection(details: details)
        ActionsSection(onSave: onSave, onCancel: onCancel)
    }
}

範例(長 body → 較短 body + 同檔案內的計算視圖):

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

4) 視圖模型處理(僅在已存在時)

  • 除非請求或現有程式碼明確要求,否則不要引入視圖模型。
  • 如果視圖模型已存在,盡可能使其非可選。
  • 透過 init 將依賴傳遞給視圖,然後在視圖的 init 中將它們傳遞給視圖模型。
  • 避免使用 bootstrapIfNeeded 模式。

範例(基於 Observation):

@State private var viewModel: SomeViewModel

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

5) Observation 使用方式

  • 對於 @Observable 參考類型,在根視圖中將其儲存為 @State。
  • 根據需要明確向下傳遞可觀察物件;除非必要,否則避免使用可選狀態。

工作流程

  1. 重新排序視圖以符合順序規則。
  2. 優先採用 MV:使用 @State、@Environment、@Query、task 和 onChange 將輕量級編排移入視圖。
  3. 如果視圖模型已存在,將可選的視圖模型替換為在 init 中初始化的非可選 @State 視圖模型,並從視圖傳遞依賴。
  4. 確認 Observation 使用方式:根 @Observable 視圖模型使用 @State,沒有冗餘的包裝器。
  5. 保持行為完整:除非有要求,否則不要更改佈局或業務邏輯。

備註

  • 偏好使用小型、明確的輔助功能,而非大型條件區塊。
  • 將計算視圖建構器放在 body 下方,非視圖的計算屬性放在 init 上方。
  • 如需 MV 優先的指導與原理,請參閱 references/mv-patterns.md。

大型視圖處理

  • 當 SwiftUI 視圖檔案超過約 300 行時,使用擴展來分組相關的輔助功能。將非同步函式和輔助函式移至專用的 private 擴展中,並使用 // MARK: - 註解來描述其用途(例如 // MARK: - 動作、// MARK: - 子視圖、// MARK: - 輔助功能)。保持主要 struct 專注於儲存屬性、init 和 body,當檔案較長時,視圖建構計算屬性也透過標記進行分組。

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

ComeOnOliver/skillshub

Create stunning, animation-rich HTML presentations from scratch or by converting PowerPoint files. Use when the user wants to build a presentation, convert a PPT/PPTX to web, or create slides for a talk/pitch. Helps non-designers discover their aesthetic through visual exploration rather than abstract choices.

ComeOnOliver/skillshub

Next.js 16+ 和 Turbopack — 增量打包、文件系统缓存、开发速度,以及何时使用 Turbopack 与 webpack。

ComeOnOliver/skillshub

SwiftUI architecture patterns, state management with @Observable, view composition, navigation, performance optimization, and modern iOS/macOS UI best practices.

ComeOnOliver/skillshub

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

ComeOnOliver/skillshub

AI-assisted video editing workflows for cutting, structuring, and augmenting real footage. Covers the full pipeline from raw capture through FFmpeg, Remotion, ElevenLabs, fal.ai, and final polish in Descript or CapCut. Use when the user wants to edit video, cut footage, create vlogs, or build video content.

ComeOnOliver/skillshub

Next.js 15 애플리케이션을 위한 프론트엔드 개발 가이드라인. React 19, TypeScript, Shadcn/ui, Tailwind CSS를 사용한 모던 패턴. Server Components, Client Components, App Router, 파일 구조, Shadcn/ui 컴포넌트, 성능 최적화, TypeScript 모범 사례 포함. 컴포넌트, 페이지, 기능 생성, 데이터 페칭, 스타일링, 라우팅, 프론트엔드 코드 작업 시 사용.

ComeOnOliver/skillshub

Provides Tamagui patterns for config v4, compiler optimization, styled context, and cross-platform styling. Must use when working with Tamagui projects (tamagui.config.ts, @tamagui imports).

ComeOnOliver/skillshub

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.

ComeOnOliver/skillshub

Create high-converting, visually distinctive landing pages. Use when building marketing pages, product launches, SaaS homepages, or any single-page conversion-focused website. Guides section-by-section composition with anti-AI-slop principles.

ComeOnOliver/skillshub

Auto-loaded context for Portfolio Buddy 2 development. Use for ANY task involving: React 19 development, TypeScript, portfolio analysis features, metrics calculations, trading strategy comparison, or working with the Portfolio Buddy 2 codebase. Contains tech stack, known issues, and architectural constraints.

ComeOnOliver/skillshub

Next.js development tooling via MCP. Inspect routes, components, build info, and debug Next.js apps. Use when working on Next.js applications, debugging routing, or inspecting app structure. NOT for general React or non-Next.js projects.

ComeOnOliver/skillshub

Implement UI using Shadcn MCP (atoms/theme) and 21st.dev MCP (complex sections). Use when adding buttons, layouts, or generating landing pages.

ComeOnOliver/skillshub

A conceptual skill for building an API client in Next.js that handles JWT tokens

ComeOnOliver/skillshub

Best practices and patterns for Next.js App Router, Server Actions, and Routing in this project.

ComeOnOliver/skillshub

The Design System, Theme, and UX rules for the Physical AI Hub.

ComeOnOliver/skillshub

Comprehensive frontend development skill for building modern, performant web applications using ReactJS, NextJS, TypeScript, Tailwind CSS. Includes component scaffolding, performance optimization, bundle analysis, and UI best practices. Use when developing frontend features, optimizing performance, implementing UI/UX designs, managing state, or reviewing frontend code.

ComeOnOliver/skillshub

This document captures learnings from fixing keyboard navigation issues when floating components (Select, DropdownMenu, Popover) have CSS open/close animations.

ComeOnOliver/skillshub

Build Next.js 16 applications with correct patterns and distinctive design. Use when creating pages, layouts, dynamic routes, upgrading from Next.js 15, or implementing proxy.ts. Covers breaking changes (async params/searchParams, Turbopack, cacheComponents) and frontend aesthetics. NOT when building non-React or backend-only applications.

ComeOnOliver/skillshub

Comprehensive Framer Motion animation library for React. Covers motion components, variants, gestures, page transitions, and scroll animations. Use when adding animations to React/Next.js applications.

ComeOnOliver/skillshub

Build interfaces that resonate, not just render. This skill enforces bold, intentional

相關技能