swiftui-patterns-developer

Applies SwiftUI view structure, composition, and MVVM patterns when refactoring iOS views.

514|79|Updated May 26, 2023
One-click install
npx skills add https://github.com/anyproto/anytype-swift --skill swiftui-patterns-developer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: swiftui-patterns-developer
Source: https://github.com/anyproto/anytype-swift/tree/main/.claude/skills/swiftui-patterns-developer
Command: npx skills add https://github.com/anyproto/anytype-swift --skill swiftui-patterns-developer

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

SwiftUI views often grow into unstructured, hard-to-maintain files with mixed business logic and inconsistent property ordering. This Skill provides concrete patterns for organizing view files, extracting subviews, and applying the MVVM architecture used in the Anytype iOS codebase.

Core Features & Use Cases

  • View Structure Standards: Enforces a consistent property ordering (property wrappers, public/private properties, computed properties, init, body, view builders, helpers) across SwiftUI view files.
  • MVVM with @Observable: Guides ViewModel creation using the @Observable macro, @State ownership, @Bindable bindings, and Factory dependency injection via @Injected.
  • View Refactoring: Splits large view bodies into computed subviews and extracted components, with ViewState enum patterns for loading/error/loaded states.
  • Use Case: When a SwiftUI view file exceeds 300 lines with business logic embedded in the body, use this Skill to extract a ViewModel, reorganize properties, and split the body into composable subviews.

Quick Start

Refactor this SwiftUI view to follow the standard view ordering and extract its business logic into an @Observable ViewModel.

Frequently Asked Questions about swiftui-patterns-developer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor a large SwiftUI view into smaller subviews?

Split the body into private computed view properties like header, filters, and results within the same file. For reusable or complex sections, extract them into separate subview structs, and use MARK extensions to organize subviews and actions when files exceed roughly 300 lines.

How to migrate from ObservableObject to @Observable in SwiftUI?

Remove ObservableObject conformance and add the @Observable macro, delete @Published from properties, and mark non-tracked properties with @ObservationIgnored. In views, change @StateObject to @State and use @Bindable when you need $ binding syntax.

When should I use @State vs @Bindable vs @Environment in SwiftUI?

Use @State when the view owns and creates the model, @Bindable when you need two-way bindings like $text for TextField, and @Environment for app-wide shared models. If a child view only reads properties, pass the model directly with no wrapper.

Should SwiftUI services use @Environment or dependency injection?

In the Anytype codebase, app services and repositories use Factory DI via @Injected, not SwiftUI Environment. @Environment is reserved for system values like dismiss and colorScheme, while business logic dependencies always go through @Injected.

Why does onAppear fire multiple times with Group and conditionals?

Wrapping conditional content in Group with lifecycle modifiers like onAppear causes the modifier to attach to each branch, firing multiple times. Replace Group with a @ViewBuilder computed property and attach the lifecycle modifier once at the top level.