- Home
- Skills
- Bluewaves Creations
- Bluewaves Skills
- Swiftui Patterns
swiftui-patterns_skill
- Shell
0
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill bluewaves-creations/bluewaves-skills --skill swiftui-patterns- SKILL.md15.6 KB
Overview
This skill presents practical guidance on modern SwiftUI architecture patterns, focusing on @Observable, view composition, state management, and the MV vs MVVM trade-offs for recent iOS/Xcode versions. It helps you choose the right pattern and wiring for real-world SwiftUI apps, from simple screens to large, testable features. The content emphasizes clear examples and best practices for iOS 17+ (iOS 26 recommended) and migration strategies for legacy code.
How this skill works
The skill inspects when to apply MV versus MVVM, how to use the @Observable macro and related property wrappers, and how to compose views and manage state across an app. It explains per-property observation, environment-based dependency injection, action-based state updates, and navigation/coordinator patterns. Concrete code examples illustrate binding, feature scoping, and constructor vs environment injection for testable design.
When to use it
- When building simple editable screens where model logic can own state (MV).
- When coordinating multiple data sources, async flows, or needing testable presentation logic (MVVM).
- When adopting iOS 17+ to use @Observable and @Bindable for better performance and per-property updates.
- When migrating an existing Combine-based codebase that needs backward compatibility with @ObservableObject.
- When structuring feature-based state or a single source-of-truth for larger apps.
Best practices
- Prefer @Observable for per-property tracking on iOS 17+; use @ObservableObject only for iOS 16 compatibility or Combine integration.
- Keep a single source of truth per feature or app root and inject it via environment for shared state.
- Extract subviews and use @ViewBuilder helpers or generic LoadingView components to keep views small and testable.
- Use constructor injection for view models and environment injection for app-wide services; provide mocks in previews and tests.
- Choose MV for minimal logic and MVVM when async operations, coordination, or testability demands separation.
Example use cases
- Quick note editor using @Observable model bound directly to view (MV).
- A notes list with async loading, search, delete and error handling implemented in a ViewModel (MVVM).
- Feature-scoped AppFeatures with separate NotesFeature and SettingsFeature injected into root environment.
- LoadingView generic component to handle idle/loading/loaded/error states for multiple screens.
- Coordinator-managed navigation path for deep linking and programmatic navigation across features.
FAQ
Keep simple validation or derived properties in the model. Move async, multi-source coordination, caching, or UI-specific presentation logic to a ViewModel for testability and separation.
How do I migrate from @ObservableObject to @Observable?
Replace @Published properties with plain vars inside an @Observable type and update views to use @Bindable or Bindable(...) bindings. Keep @ObservableObject when targeting iOS versions before iOS 17 or when Combine integration is required.