
Swiftui Patterns
Apply modern SwiftUI state, NavigationStack, composition, and performance patterns when a solo iOS or macOS builder ships native UI with agents.
Overview
SwiftUI Patterns is an agent skill most often used in Build (also Ship perf review) that documents @Observable state, NavigationStack, composition, and rendering performance for Apple platforms.
Install
npx skills add https://github.com/affaan-m/everything-claude-code --skill swiftui-patternsWhat is this skill?
- Property-wrapper decision table: @State, @Binding, @Observable, @Bindable, @Environment
- @Observable view models for property-level invalidation vs ObservableObject
- NavigationStack and type-safe navigation flows
- View composition, environment injection, list and layout performance
- Activate for managing state, sheets, and complex SwiftUI trees
- Property-wrapper selection table covering six SwiftUI wrappers
Adoption & trust: 4.6k installs on skills.sh; 210k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your agent keeps generating SwiftUI with ObservableObject boilerplate, full-view redraws, and fragile navigation that does not match current Apple APIs.
Who is it for?
Indie developers building SwiftUI iOS or macOS apps who want agents to follow Observation-era patterns instead of outdated Combine-heavy templates.
Skip if: Cross-platform Flutter or React Native projects, or teams that only maintain UIKit storyboards with no SwiftUI surface area.
When should I use this skill?
Building SwiftUI views, NavigationStack flows, view models, performance for lists and layouts, or environment-based dependency injection.
What do I get? / Deliverables
You get consistent SwiftUI architecture guidance—wrapper selection, observable view models, and performance-minded list patterns—applied across new screens and refactors.
- View and view-model structure aligned with @Observable patterns
- Navigation and state-handling conventions for agent-generated SwiftUI files
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Primary work is implementing Apple-platform UI in the product—canonical shelf is Build frontend even though patterns also help during ship-time perf passes. Frontend subphase covers declarative views, observation-driven re-renders, and navigation structure for shipped apps.
Where it fits
Scaffold a settings flow with @Observable store and NavigationStack destinations instead of nested NavigationLinks.
Audit a long feed for unnecessary body recomputation after observation boundaries are wrong.
Refactor legacy ObservableObject screens to @Observable without breaking environment injection.
How it compares
Use as a procedural pattern sheet for native SwiftUI—not a UI kit generator or App Store marketing skill.
Common Questions / FAQ
Who is swiftui-patterns for?
Solo and indie builders shipping SwiftUI on Apple platforms who need agent-ready guidance on state, navigation, and performance.
When should I use swiftui-patterns?
During Build when adding views and view models; during Ship perf subphase when lists stutter; during Operate iterate when refactoring navigation or observation boundaries.
Is swiftui-patterns safe to install?
It is documentation-only patterns with no required shell or network tools—still review the Security Audits panel on this page before adding any skill to your agent.
SKILL.md
READMESKILL.md - Swiftui Patterns
# SwiftUI Patterns Modern SwiftUI patterns for building declarative, performant user interfaces on Apple platforms. Covers the Observation framework, view composition, type-safe navigation, and performance optimization. ## When to Activate - Building SwiftUI views and managing state (`@State`, `@Observable`, `@Binding`) - Designing navigation flows with `NavigationStack` - Structuring view models and data flow - Optimizing rendering performance for lists and complex layouts - Working with environment values and dependency injection in SwiftUI ## State Management ### Property Wrapper Selection Choose the simplest wrapper that fits: | Wrapper | Use Case | |---------|----------| | `@State` | View-local value types (toggles, form fields, sheet presentation) | | `@Binding` | Two-way reference to parent's `@State` | | `@Observable` class + `@State` | Owned model with multiple properties | | `@Observable` class (no wrapper) | Read-only reference passed from parent | | `@Bindable` | Two-way binding to an `@Observable` property | | `@Environment` | Shared dependencies injected via `.environment()` | ### @Observable ViewModel Use `@Observable` (not `ObservableObject`) — it tracks property-level changes so SwiftUI only re-renders views that read the changed property: ```swift @Observable final class ItemListViewModel { private(set) var items: [Item] = [] private(set) var isLoading = false var searchText = "" private let repository: any ItemRepository init(repository: any ItemRepository = DefaultItemRepository()) { self.repository = repository } func load() async { isLoading = true defer { isLoading = false } items = (try? await repository.fetchAll()) ?? [] } } ``` ### View Consuming the ViewModel ```swift struct ItemListView: View { @State private var viewModel: ItemListViewModel init(viewModel: ItemListViewModel = ItemListViewModel()) { _viewModel = State(initialValue: viewModel) } var body: some View { List(viewModel.items) { item in ItemRow(item: item) } .searchable(text: $viewModel.searchText) .overlay { if viewModel.isLoading { ProgressView() } } .task { await viewModel.load() } } } ``` ### Environment Injection Replace `@EnvironmentObject` with `@Environment`: ```swift // Inject ContentView() .environment(authManager) // Consume struct ProfileView: View { @Environment(AuthManager.self) private var auth var body: some View { Text(auth.currentUser?.name ?? "Guest") } } ``` ## View Composition ### Extract Subviews to Limit Invalidation Break views into small, focused structs. When state changes, only the subview reading that state re-renders: ```swift struct OrderView: View { @State private var viewModel = OrderViewModel() var body: some View { VStack { OrderHeader(title: viewModel.title) OrderItemList(items: viewModel.items) OrderTotal(total: viewModel.total) } } } ``` ### ViewModifier for Reusable Styling ```swift struct CardModifier: ViewModifier { func body(content: Content) -> some View { content .padding() .background(.regularMaterial) .clipShape(RoundedRectangle(cornerRadius: 12)) } } extension View { func cardStyle() -> some View { modifier(CardModifier()) } } ``` ## Navigation ### Type-Safe NavigationStack Use `NavigationStack` with `NavigationPath` for programmatic, type-safe routing: ```swift @Observable final class Router { var path = NavigationPath() func navigate(to destination: Destination) { path.append(destination) } func popToRoot() { path = NavigationP