スキル一覧に戻る
co-labs-co

swiftui-mvvm-pattern

by co-labs-co

Central skills repository for ContextHarness - curated agent skills and workflows

0🍴 0📅 2026年1月12日
GitHubで見るManusで実行

SKILL.md


name: swiftui-mvvm-pattern version: 0.1.0 author: cmtzco description: iOS SwiftUI MVVM architectural pattern implementation guide. When to use: when creating new views, implementing data binding between UI and business logic, adding screens to SwiftUI apps, or working with state management in iOS. What problems it solves: provides clear separation of concerns, enables reusable business logic, makes state management predictable with @Published properties, and follows iOS best practices for SwiftUI apps.

SwiftUI MVVM Pattern

Overview

The Model-View-ViewModel (MVVM) pattern is standard architectural approach for SwiftUI applications. This skill guides you through implementing ViewModels that expose @Published properties, Views that use @StateObject to inject ViewModels, and proper data flow between the two layers.

Identified Patterns

The following patterns were identified in this codebase that this skill addresses:

Pattern 1: ObservableObject ViewModel

  • Location: DadBrain/DadBrain/ViewModels/MemoryListViewModel.swift
  • Description: Class conforming to ObservableObject with @Published properties for state management
  • Frequency: Found in 5 ViewModels (MemoryListViewModel, VoiceRecorder, PhotoScanner, KeywordExtractor, MemorySummarizer)

Pattern 2: @StateObject View Injection

  • Location: DadBrain/DadBrain/Views/MemoriesListView.swift
  • Description: SwiftUI Views using @StateObject to create and own ViewModels
  • Frequency: Found in 7 View files using consistent injection pattern

Pattern 3: @Environment Object Dependency Injection

  • Location: DadBrain/DadBrain/Views/MemoriesListView.swift
  • Description: Using @Environment for shared dependencies like Core Data contexts
  • Frequency: Used across multiple views for PersistenceController

TODO: Implementation

This skeleton skill needs Phase 2 refinement. Areas to develop:

Workflow Instructions

  1. Create ViewModel class with ObservableObject
  2. Add @Published properties for observable state
  3. Create View with @StateObject injection
  4. Bind View UI to ViewModel properties
  5. Handle user actions in ViewModel methods

Best Practices

  • When to use @StateObject vs @ObservedObject
  • Dependency injection patterns
  • Testing ViewModels in isolation
  • Handling async operations in ViewModels

Common Pitfalls

  • Memory leaks with improper object lifecycle
  • State synchronization issues
  • Over-complicating ViewModels with view logic
  • Missing @Published on properties that should trigger updates

Suggested Resources

Based on codebase analysis, consider adding:

Scripts (scripts/)

  • mvvm-viewmodel-generator.swift - Generates ViewModel boilerplate from entity definitions
  • mvvm-view-generator.swift - Creates View scaffolds with proper StateObject injection

References (references/)

  • apple-swiftui-data-flow.md - Apple's official documentation on data flow
  • stateobject-vs-observedobject.md - When to use each property wrapper
  • mvvm-testing-patterns.md - Testing strategies for ViewModels

Assets (assets/)

  • viewmodel-templates/ - Swift templates for different ViewModel scenarios
  • view-templates/ - SwiftUI View templates with MVVM structure

Evidence from Codebase

FilePatternRelevance
DadBrain/DadBrain/ViewModels/MemoryListViewModel.swiftObservableObject with @Published propertiesCore ViewModel pattern example
DadBrain/DadBrain/ViewModels/VoiceRecorder.swiftAsync operations in ViewModelShows handling of Speech Framework
DadBrain/DadBrain/Views/MemoriesListView.swift@StateObject and @Environment usageView layer pattern example
DadBrain/DadBrain/Views/MemoryDetailView.swiftNavigation and data passingShows navigation between MVVM screens

Refinement Priority

Score: 8.4/10 Priority: High

Refinement Tasks

  1. Research Apple's SwiftUI data flow documentation
  2. Create mvvm-viewmodel-generator script
  3. Document state management patterns and property wrappers
  4. Add examples from MemoryListViewModel and other ViewModels
  5. Create testing guide for ViewModels

Skeleton generated by ContextHarness /baseline Run Phase 2 skill refinement to complete implementation

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です