# Swift SwiftUI

> Standards for State Management, View Lifecycle, and Property Wrappers

- Skill: `fierzone/swift-swiftui` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add fierzone/swift-swiftui`
- Raw SKILL.md: https://api.skillmd.com/api/skills/fierzone/swift-swiftui/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: fierzone (https://skillmd.com/u/fierzone)
- Updated: 2026-09-10
- Page: https://skillmd.com/skills/fierzone/swift-swiftui

---


# SwiftUI Standards

## **Priority: P0**

## Implementation Guidelines

### State Management

- **@State**: Private UI state owned by the view (e.g., toggle, text input).
- **@Binding**: Two-way connection to parent's @State.
- **@ObservedObject**: Reference to external observable object.
- **@StateObject**: View owns the lifecycle of the object.
- **@EnvironmentObject**: Shared data across view hierarchy.

### View Composition

- **Extract Subviews**: Keep views small (<200 lines). Extract reusable components.
- **View Modifiers**: Chain modifiers for styling (`.font()`, `.padding()`).
- **Custom Modifiers**: Create `ViewModifier` for reusable styles.

### Performance

- **Avoid Heavy Computation**: Use `@State` + `.task()` for async work.
- **Equatable**: Conform views to `Equatable` to prevent unnecessary re-renders.
- **LazyStacks**: Use `LazyVStack`/`LazyHStack` for large lists.

## Anti-Patterns

- **@ObservedObject Ownership**: `**No @ObservedObject for owned objects**: Use @StateObject.`
- **Heavy body**: `**No logic in body**: Move to computed properties or methods.`
- **Force Unwrap in Views**: `**No ! in View**: Use if-let or nil coalescing.`

## References

- [State & Binding](references/implementation.md)

