swiftui-patterns
Installation
SKILL.md
SwiftUI Patterns (iOS 17+)
SwiftUI 17+ removes ObservableObject boilerplate with @Observable, simplifies environment injection with @Environment, and introduces task-based async patterns. The core principle: use Apple's modern APIs instead of reactive libraries.
Overview
Quick Reference
| Need | Use (iOS 17+) | NOT |
|---|---|---|
| Observable model | @Observable |
ObservableObject |
| Published property | Regular property | @Published |
| Own state | @State |
@StateObject |
| Passed model (binding) | @Bindable |
@ObservedObject |
| Environment injection | environment(_:) |
environmentObject(_:) |
| Environment access | @Environment(Type.self) |
@EnvironmentObject |
| Async on appear | .task { } |
.onAppear { Task {} } |
| Value change | onChange(of:initial:_:) |
onChange(of:perform:) |