{"enrichment":{"faq":[{"a":"swiftui-patterns teaches that @Observable is SwiftUI's modern state management macro, replacing ObservableObject for cleaner syntax. Mark your model class with @Observable, then reference it directly in views without @StateObject. The macro automatically tracks property changes and triggers view updates only when accessed properties change, reducing unnecessary re-renders and simplifying dependency injection across your app.","q":"How do you use @Observable in SwiftUI for state management?"},{"a":"swiftui-patterns emphasizes using @Observable for view models, @State for local view state, and @Environment for injected dependencies. Avoid ObservableObject when possible. Keep state as close to where it's used as possible, use @Binding to pass state down, and leverage @Query for data fetching. This layered approach prevents over-rendering and maintains clear data flow in scalable architectures.","q":"What are the best practices for SwiftUI state management?"},{"a":"swiftui-patterns shows that NavigationStack replaces NavigationLink with a data-driven approach using a NavigationPath or typed array. Define your route as an enum, bind the stack to your state, and push routes programmatically. This pattern provides compile-time safety, easier testing, and centralized navigation logic\u2014essential for building maintainable multi-screen apps.","q":"How does NavigationStack enable type-safe routing in SwiftUI?"},{"a":"swiftui-patterns demonstrates using LazyVStack and LazyHStack for large lists, extracting subviews to reduce body complexity, and applying @ViewBuilder for conditional composition. Stable identifiers in ForEach prevent re-creation of views, and custom view modifiers encapsulate reusable styles. These patterns minimize view hierarchy depth and prevent unnecessary recalculation of expensive views.","q":"What view composition patterns improve SwiftUI performance?"},{"a":"swiftui-patterns recommends injecting dependencies through @Environment and initializer parameters rather than global singletons. Use @Observable models as environment objects, pass them explicitly to child views, and leverage @Query for database access. This approach improves testability, reduces coupling, and makes data dependencies explicit and traceable throughout your view hierarchy.","q":"How should you structure dependency injection in SwiftUI?"},{"a":"swiftui-patterns advocates for @Observable-based view models, NavigationStack for routing, and environment-driven dependency injection. Combine these with task-based async/await for data loading and stable ForEach identifiers for list rendering. This contemporary approach eliminates legacy patterns, improves performance, and creates scalable, testable architectures aligned with current SwiftUI best practices.","q":"What modern SwiftUI architecture patterns should you adopt in 2024?"}],"shadow_tags":["reactive-ui-framework","property-wrapper-guide","declarative-layout","ios-macos-development","performance-tuning","navigation-routing","view-lifecycle","state-flow-architecture","modern-swift-patterns"],"summary_rewrite":"Explore contemporary SwiftUI architecture through practical state management examples built around the @Observable macro. This collection demonstrates how to structure reactive components and manage data flow efficiently in modern iOS applications, helping developers move beyond legacy patterns."},"files":[{"bytes":7306,"path":"skills/swiftui-patterns/SKILL.md","sha256":"e8c4a8ce1034be337c9a4b6414c2bf5eaecf0b925bd6e5b0a2507643dbcdad5b","url":"https://skillfed.io/files/xu-xiang/everything-claude-code-zh/swiftui-patterns/539033e0/SKILL.md"}],"id":"xu-xiang/everything-claude-code-zh/swiftui-patterns","links":{"html":"https://skillfed.io/xu-xiang/everything-claude-code-zh/swiftui-patterns","md":"https://skillfed.io/xu-xiang/everything-claude-code-zh/swiftui-patterns.md","repo":"https://github.com/xu-xiang/everything-claude-code-zh"},"meta":{"agents_supported":[],"first_seen":"2026-07-28","forks":298,"language":"JavaScript","last_updated":"2026-03-05","license":"MIT","name":"swiftui-patterns","publisher":"xu-xiang","stars":1767},"relations":{"similar":[{"id":"affaan-m/ECC/swiftui-patterns"},{"id":"travisjneuman/.claude/ios-development"},{"id":"Mindrally/skills/swiftui-development"},{"id":"Aradotso/ai-agent-skills/swiftui-agent-skill"},{"id":"dpearson2699/swift-ios-skills/swiftui-patterns"},{"id":"miles990/claude-software-skills/swift"},{"id":"pproenca/dot-skills/swift-refactor"},{"id":"rshankras/claude-code-apple-skills/state-restoration"},{"id":"rshankras/claude-code-apple-skills/architecture-spec"},{"id":"personamanagmentlayer/pcl/swift-expert"}]},"slug":{"owner":"xu-xiang","repo":"everything-claude-code-zh","skill":"swiftui-patterns"},"version":"539033e0"}
