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
ViewModifierfor reusable styles.
Performance
- Avoid Heavy Computation: Use
@State+.task()for async work. - Equatable: Conform views to
Equatableto prevent unnecessary re-renders. - LazyStacks: Use
LazyVStack/LazyHStackfor 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
More from hoangnguyen0403/agent-skills-standard
java-language
Modern Java 21+ standards including Records, Pattern Matching, and Virtual Threads. Use when working with Java records, sealed classes, switch expressions, text blocks, Optional, or upgrading from older Java versions. (triggers: **/*.java, pom.xml, build.gradle, record, sealed, switch, var, Optional, stream, VirtualThread, instanceof, text block)
1swift tooling
Standards for SPM, Build Configs, and Code Quality
1swift testing
Standards for XCTest, Async Tests, and Test Organization
1swift language
Standards for Optionals, Protocols, Extensions, and Type Safety
1java-concurrency
Implement modern concurrency with Virtual Threads and Structured Concurrency in Java. Use when implementing Java Virtual Threads (Java 21), Structured Concurrency with StructuredTaskScope, CompletableFuture pipelines, or debugging race conditions. (triggers: **/*.java, Thread, Executor, synchronized, lock, CompletableFuture, StructuredTaskScope, VirtualThread, AtomicInteger, async, race condition)
1dart tooling & ci
Standards for analysis, linting, formatting, and automation.
1