Communitygithub.com

ComeOnOliver/skillshub

SwiftUIビューファイルをリファクタリングし、一貫した構造、依存性注入、Observationの使用を標準化します。SwiftUIビューのレイアウトや順序を整理したり、ビューモデルを安全に(可能な限り非オプショナルで)扱ったり、依存関係や@Observableの状態を初期化・受け渡しする方法を統一する際に使用します。

skillshub とは?

このスキルは、SwiftUIビューをリファクタリングするための一貫した構造と依存関係パターンを適用します。主な目的は、ビューの宣言順序(Environment→プロパティ→init→bodyなど)、Model-View(MV)パターンの推奨、ビューモデルの安全な取り扱い、そして@ObservableによるObservationの適切な使用に焦点を当てています。このスキルはClaude CodeやCursorなどのAIエージェント向けに設計されており、SKILL.mdに定義された明確なガイドラインに従って、SwiftUIのコードベースをより保守しやすく、読みやすくします。具体的には、ビューの分割、依存性注入のパターン、ビューモデルの非オプショナル化、そして大規模なビューファイルを拡張機能とマークコメントで整理する方法を提供します。開発者は、このスキルを使用することで、SwiftUIプロジェクトのコード品質を向上させ、チーム全体で一貫したアーキテクチャを維持できます。

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

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

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 の下に、ビュー以外の計算型varは init の上に配置します。
  • MVファーストのガイダンスと根拠については、references/mv-patterns.md を参照してください。

大規模ビューの取り扱い

  • SwiftUIビューファイルが約300行を超える場合、拡張機能を使用して関連するヘルパーをグループ化します。非同期関数やヘルパー関数は、専用の private 拡張機能に移動し、その目的を説明する // MARK: - コメント(例: // MARK: - Actions、// MARK: - Subviews、// MARK: - Helpers)で区切ります。メインの struct は格納プロパティ、init、および body に集中させ、ファイルが長い場合はビュー生成計算型varもマークでグループ化します。

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

関連スキル