ios-swiftuilisted
Install: claude install-skill ebbaunqualified520/ios-agent-skills
# iOS SwiftUI Expert Skill
## Core Rules
1. **Use @Observable (iOS 17+) over ObservableObject** — fine-grained property tracking, better performance, simpler syntax.
2. **Use @State to own @Observable instances**, NOT @StateObject. `@StateObject` is the pre-iOS 17 pattern.
3. **Use NavigationStack** (not NavigationView) with value-based `NavigationLink` + `.navigationDestination`.
4. **Never nest NavigationStack inside NavigationStack** — causes double navigation bars and broken behavior.
5. **Use LazyVStack/LazyHStack inside ScrollView** for large collections. Use `List` for very large datasets (cell reuse + prefetching).
6. **Keep `body` pure** — no data processing, network calls, or side effects. Use `.task` modifier for async work.
7. **Avoid `AnyView`** — it destroys view identity and kills diffing performance. Use `@ViewBuilder` or `Group` instead.
8. **Preserve view identity** — use ternary operators (`condition ? viewA : viewB`), not `if/else` that changes the view type in ways that break animations.
9. **Break large views into small subviews** — SwiftUI re-evaluates `body` often; smaller views = smaller re-evaluation scope.
10. **Use `.equatable()`** on expensive views to skip unnecessary re-renders.
---
## Decision Tables
### State Management — What to Use When
| Scenario | iOS 17+ | Pre-iOS 17 |
|---|---|---|
| Simple value owned by view | `@State` | `@State` |
| Pass value down for read/write | `@Binding` | `@Binding` |
| Reference-type model owned by view |