What does this skill do?

The SwiftUI Modern Patterns Skill provides the correct conventions and patterns for building modern SwiftUI apps, avoiding deprecated APIs such as ObservableObject or @StateObject. It applies the Observation framework with property-level tracking, typed navigation with NavigationStack, and rendering optimization to create high-performance declarative interfaces on iOS and macOS.

State Management with @Observable
Create view models with @Observable so that SwiftUI only re-renders the views that read the property that has changed.
Typed Navigation with NavigationStack
Implement an observable router with hashable enums as destinations, avoiding fragile strings.
Dependency Injection with @Environment
Inject dependencies using .environment() and consume them with @Environment, replacing @EnvironmentObject.
Rendering Optimization
Break large views down into smaller subviews, use LazyVStack, and use stable identifiers in ForEach.

Usage examples

🔄 View model with @Observable
Create a view model with @Observable for a list of products with search and asynchronous loading using .task.
🧭 Typed Navigation
Implement typed navigation using NavigationStack and an observable router for an e-commerce app with destinations for product details and settings.
🔧 Legacy Code Refactoring
Refactor this code, which uses `ObservableObject` and `@StateObject`, to use the modern `@Observable`, and explain the changes to me.
⚡ List Optimization
Optimize this SwiftUI list so that it only re-renders the rows that change, using LazyVStack and stable identifiers.

Features

Tracking at the property level With @Observable, SwiftUI re-renders only the views that read the modified property, not the entire hierarchy.
Typed Programmatic Navigation Use NavigationStack with NavigationPath and Hashable enums for safe and predictable routes.
Modern Dependency Injection Replace @EnvironmentObject with @Environment and .environment() for cleaner, type-safe injection.
Composition of Views and ViewModifiers Break large views into smaller subviews and create reusable styles with ViewModifier.
Identifying Anti-Patterns Avoid AnyView, ObservableObject, asynchronous operations in the `body` or `init` methods, and Sendable violations when communicating with actors.

Frequently asked questions

Patterns using @Observable require iOS 17+ and macOS 14+ (Swift 5.9). The skill clearly indicates which APIs are legacy and which are modern.
Yes. The skill identifies anti-patterns (ObservableObject, @Published, @StateObject, @EnvironmentObject) and guides you through migrating them to @Observable in an incremental manner.
No. It's a pattern- and architecture-based skill that generates SwiftUI code directly; it doesn't require connecting to any MCP or external service.
Yes. It shows how to create #Preview using mocks and test repositories for each state of the view (loading, empty, with data).
SwiftUI Modern Patterns — Modern iOS Architecture with Claude AI

¿Prefieres escuchar el contenido? Genera la narración de audio con un clic.