Learn SwiftUI architecture, state management, navigation, and performance best practices.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "swiftui-patterns" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/swiftui-patterns/SKILL.md 2. Save it as ~/.claude/skills/swiftui-patterns/SKILL.md 3. Reload skills and tell me it's ready
I am building a SwiftUI form with text fields, toggles, parent-child state sharing, and shared dependencies. Explain when to use @State, @Binding, @Observable, @Bindable, and @Environment, with short examples.
A scenario-based recommendation for state management, with matching SwiftUI code examples.
Please refactor this SwiftUI list screen from ObservableObject to @Observable, and explain how the view should own it, handle loading state, and bind searchable text.
Refactored ViewModel and View code, plus an explanation of the migration approach.
I have a SwiftUI order screen with frequent state changes. Please refactor the view structure using small, focused subviews to reduce unnecessary re-rendering, and explain why.
A refactored view structure showing which subviews should read which state to improve performance.
iOS or macOS developers can use it to structure declarative UI, state sources, and data flow. It is especially useful when deciding between @State, @Binding, and @Observable.
When an app uses NavigationStack for screen transitions, this skill provides pattern guidance. It is useful for planning navigation structure and view composition.
If SwiftUI lists or complex layouts suffer from excessive re-rendering or slow rendering, its performance guidance can help. The focus is reducing unnecessary updates through finer-grained view decomposition.
The documentation introduces modern SwiftUI patterns for building declarative and performant interfaces on Apple platforms. It covers state management choices, view composition, type-safe navigation, and performance optimization. The excerpt explains when to use @State, @Binding, @Observable, @Bindable, and @Environment, and shows examples of building an @Observable view model, owning it inside a view, injecting dependencies, and reducing invalidation by extracting focused subviews.
Modern SwiftUI patterns for building declarative, performant user interfaces on Apple platforms. Covers the Observation framework, view composition, type-safe navigation, and performance optimization.
@State, @Observable, @Binding)NavigationStackChoose 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() |
Use @Observable (not ObservableObject) — it tracks property-level changes so SwiftUI only re-renders views that read the changed property:
@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()) ?? []
}
}
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() }
}
}
Replace @EnvironmentObject with @Environment:
// Inject
ContentView()
.environment(authManager)
// Consume
struct ProfileView: View {
@Environment(AuthManager.self) private var auth
var body: some View {
Text(auth.currentUser?.name ?? "Guest")
}
}
Break views into small, focused structs. When state changes, only the subview reading that state re-renders:
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)
}
}
}
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())
}
}
Use NavigationStack with NavigationPath for programmatic, type-safe routing:
@Observable
final class Router {
var path = NavigationPath()
func navigate(to destination: Destination) {
path.append(destination)
}
func popToRoot() {
path = NavigationPath()
}
}
enum Destination: Hashable {
case detail(Item.ID)
case settings
case profile(User.ID)
}
struct RootView: View {
@State private var router = Router()
…
It focuses on modern SwiftUI development patterns, including architecture, state management, view composition, navigation, and performance optimization. The docs also mention the Observation framework, environment injection, and Apple platform UI best practices.
The documentation explicitly recommends using @Observable instead of ObservableObject. For shared dependency injection, the example shows using @Environment with .environment() instead of @EnvironmentObject.
The provided excerpt does not include installation steps or full prerequisites. It clearly targets SwiftUI and Apple platform development; for more details, see the source repository.
Get expert guidance for building and maintaining apps with the tinystruct Java framework.
Use the correct Ethereum Keccak-256 hashing in Node.js and TypeScript.
Get practical Docker and Compose patterns for secure local multi-service development.
Safely automate SSH collection, parsing, and controlled network changes with Netmiko.
Lets users choose response depth and token usage before answering.
Review prediction-market workflows for compliance, safety, privacy, and execution risks.
Learn frontend patterns for React, Next.js, state, performance, and UI best practices.
Apply Compose Multiplatform patterns for UI architecture, navigation, theming, and performance.
Write and review React 18/19 components using modern best practices.
Access SwiftUI components and full-stack recipes instantly via MCP.
Learn Django architecture, DRF API design, and production-ready development practices.
Learn idiomatic Rust patterns, ownership, concurrency, and robust error handling practices.