dpearson2699/swift-ios-skills / skills/swiftui-patterns
swiftui-patterns
VerifiedBuilds and reviews SwiftUI views with modern MV architecture, state, composition, isolated previews, and migration guidance. Covers @Observable ownership, @State/@Bindable/@Environment wiring, view decomposition, ViewModifiers, environment values, .task loading, iOS 26+ handoffs, Writing Tools, clipboard availability, and performance. Use when structuring SwiftUI state, managing @Observable, composing views, previewing meaningful UI states, or correcting SwiftUI patterns.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 19.3 KB |
| evals/evals.json | config | 8.5 KB |
| references/architecture-patterns.md | markdown | 16.8 KB |
| references/deprecated-migration.md | markdown | 30.9 KB |
| references/design-polish.md | markdown | 23.4 KB |
| references/platform-and-sharing.md | markdown | 19.0 KB |
| references/preview-isolation.md | markdown | 2.6 KB |
| references/view-refactoring.md | markdown | 3.6 KB |
references/preview-isolation.md
View on GitHub# Isolated Preview Construction
Use previews as deterministic compositions of a view's required inputs. A preview should render without launching the full app or reaching production services.
## Cover Meaningful States
Provide separate previews for the states that materially change the interface:
- loaded content with representative data
- meaningful loading or refreshing UI
- empty content and its primary recovery action
- recoverable and terminal error presentations when they differ
Skip state permutations that do not change layout, behavior, or accessibility.
## Install Required Dependencies
Keep production dependencies required. Install every environment value, observable model, action, and persistence container the view expects instead of making a dependency optional to silence a preview failure.
```swift
@MainActor
private struct ProfilePreview: View {
let state: ProfileStore.State
var body: some View {
ProfileScreen()
.environment(ProfileStore.preview(state: state))
.environment(\.profileClient, .preview)
}
}
#Preview("Loaded") {
ProfilePreview(state: .loaded(.fixture))
}
#Preview("Loading") {
ProfilePreview(state: .loading)
}
#Preview("Empty") {
ProfilePreview(state: .empty)
}
#Preview("Error") {
ProfilePreview(state: .failed(.fixture))
}
```
When a view requires SwiftData, use a seeded in-memory `ModelContainer`. Apply the same rule to caches and file stores: create isolated temporary or in-memory fixtures.
## Keep Fixtures Deterministic
- Use fixed identifiers, dates, locale-sensitive values, and image dimensions.
- Make preview clients return fixture results immediately or after a controlled delay.
- Keep fixtures small but representative enough to exercise wrapping, truncation, and empty/error affordances.
- Put reusable preview factories next to the model or in preview-only support code; do not hide them behind production singletons.
Never depend on live networking, authentication state, production databases, keychain contents, or global singleton state. These inputs make previews slow, flaky, order-dependent, or destructive.
## Review Checklist
- [ ] Loaded plus meaningful loading, empty, and error states are represented
- [ ] Fixtures are fixed and repeatable
- [ ] Every required environment dependency is installed
- [ ] Persistence is in-memory or temporary and seeded locally
- [ ] No live service, authentication, production data, keychain, or global singleton is required
- [ ] Required production dependencies remain nonoptional
> **Apple session:** [Visually edit SwiftUI views](https://sosumi.ai/videos/play/wwdc2020/10185)
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation). | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults. | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |
| mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK). | Stars: 198k | Updated | Claude CodeCodex | Verified | Install |