swift-patterns
Skill10 starsChanged 9 months agoMITView on GitHub
Review, refactor, or build SwiftUI features with correct state management, modern API usage, optimal view composition, navigation patterns, performance optimization, and testing best practices.
2 other projects use a version of this.
Adopted by
Most recently taken up by
- ahmed3elshaer/everything-claude-code-mobiletheir own version, first seen Jun 14, 2026
- harshii0509/swift-skill-packtheir own version, first seen Jun 1, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- ahmed3elshaer/everything-claude-code-mobile★ 66same name
- harshii0509/swift-skill-pack★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repositoryOne other file it gives its agents.
- AGENTS.mdAGENTS.md
The file
Show its rules and text
We split this skill into the rules it gives an agent
17 rules. About 0 are common, 6 are distinctive, and 11 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
11
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 14
Check state management against property wrapper selection (see references/state.md)
- Very specific: line 15
Verify view composition and extraction patterns (see references/view-composition.md)
- Very specific: line 18
Check async work patterns with .task (see references/concurrency.md)
- Very specific: line 19
Verify navigation implementation (see references/navigation.md)
- Distinctive: line 20
Use Review Response Template (below)
- Distinctive: line 29
Use Refactor Response Template (below)
- Very specific: line 34
Use modern APIs only (see references/modern-swiftui-apis.md)
- Very specific: line 71
Always mark @State as private (makes ownership explicit)
- Very specific: line 72
Never use @State for passed values (accepts initial value only)
- Very specific: line 73
Use @State with @Observable classes (not @StateObject)
- Distinctive: line 93
Use this when reviewing SwiftUI code:
- Very specific: line 142
No Swift concurrency patterns: - Use .task for SwiftUI async work
- Very specific: line 143
No architecture mandates: - Don't require MVVM/MVC/VIPER or specific structures
- Distinctive: line 145
No tool-specific guidance: - No Xcode, Instruments, or IDE instructions
- Distinctive: line 148
All workflows must follow these constraints.
- Distinctive: line 157
No architectural mandates (MVVM/VIPER not required)
- Very specific: line 162
All references in references/:
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
swift-patterns
Review, refactor, or build SwiftUI features with correct state management, modern API usage, optimal view composition, and performance-conscious patterns. Prioritize native APIs, Apple design guidance, and testable code structure. This skill focuses on facts and best practices without enforcing specific architectural patterns.
Workflow Decision Tree
1) Review existing SwiftUI code
→ Read references/workflows-review.md for review methodology
- Check state management against property wrapper selection (see
references/state.md) - Verify view composition and extraction patterns (see
references/view-composition.md) - Audit list performance and identity stability (see
references/lists-collections.md) - Validate modern API usage (see
references/modern-swiftui-apis.md) - Check async work patterns with .task (see
references/concurrency.md) - Verify navigation implementation (see
references/navigation.md) - Use Review Response Template (below)
2) Refactor existing SwiftUI code
→ Read references/workflows-refactor.md for refactor methodology
- Extract complex views using playbooks (see
references/refactor-playbooks.md) - Migrate deprecated APIs to modern equivalents (see
references/modern-swiftui-apis.md) - Optimize performance hot paths (see
references/performance.md) - Restructure state ownership (see
references/state.md) - Apply common patterns (see
references/patterns.md) - Use Refactor Response Template (below)
3) Implement new SwiftUI features
- Design data flow first: identify owned vs injected state (see
references/state.md) - Structure views for optimal composition (see
references/view-composition.md) - Use modern APIs only (see
references/modern-swiftui-apis.md) - Handle async work with .task modifier (see
references/concurrency.md) - Apply performance patterns early (see
references/performance.md) - Implement navigation flows (see
references/navigation.md)
4) Answer best practice questions
- Load relevant reference file(s) based on topic (see Reference Files below)
- Provide direct guidance with examples
If intent unclear, ask: "Do you want findings only (review), or should I change the code (refactor)?"
Response Templates
Review Response:
- Scope - What was reviewed
- Findings - Grouped by severity with actionable statements
- Evidence - File paths or code locations
- Risks and tradeoffs - What could break or needs attention
- Next steps - What to fix first or verify
Refactor Response:
- Intent + scope - What is being changed and why
- Changes - Bulleted list with file paths
- Behavior preservation - What should remain unchanged
- Next steps - Tests or verification needed
Quick Reference: Property Wrapper Selection
| Wrapper | Use When | Ownership |
@State | Internal view state (value type or @Observable class) | View owns |
@Binding | Child needs to modify parent's state | Parent owns |
@Bindable | Injected @Observable object needing bindings | Injected |
let | Read-only value from parent | Injected |
var + .onChange() | Read-only value needing reactive updates | Injected |
Key rules:
- Always mark
@Stateasprivate(makes ownership explicit) - Never use
@Statefor passed values (accepts initial value only) - Use
@Statewith@Observableclasses (not@StateObject)
See references/state.md for detailed guidance and tradeoffs.
Quick Reference: Modern API Replacements
| Deprecated | Modern Alternative | Notes |
foregroundColor() | foregroundStyle() | Supports dynamic type |
cornerRadius() | .clipShape(.rect(cornerRadius:)) | More flexible |
NavigationView | NavigationStack | Type-safe navigation |
tabItem() | Tab API | iOS 18+ |
onTapGesture() | Button | Unless need location/count |
onChange(of:) { value in } | onChange(of:) { old, new in } or onChange(of:) { } | Two or zero parameters |
UIScreen.main.bounds | GeometryReader or layout APIs | Avoid hard-coded sizes |
See references/modern-swiftui-apis.md for complete migration guide.
Review Checklist
Use this when reviewing SwiftUI code:
State Management
@Stateproperties markedprivate- Passed values NOT declared as
@Stateor@StateObject @Bindingonly where child modifies parent state- Property wrapper selection follows ownership rules
- State ownership clear and intentional
Modern APIs
- No deprecated modifiers (foregroundColor, cornerRadius, etc.)
- Using
NavigationStackinstead ofNavigationView - Using
Buttoninstead ofonTapGesturewhen appropriate - Using two-parameter or no-parameter
onChange()
View Composition
- Using modifiers over conditionals for state changes (maintains identity)
- Complex views extracted to separate subviews
- Views kept small and focused
- View
bodysimple and pure (no side effects)
Navigation & Sheets
- Using
navigationDestination(for:)for type-safe navigation - Using
.sheet(item:)for model-based sheets - Sheets own their dismiss actions
Lists & Collections
ForEachuses stable identity (never.indicesfor dynamic data)- Constant number of views per
ForEachelement - No inline filtering in
ForEach(prefilter and cache) - No
AnyViewin list rows
Performance
- Passing only needed values to views (not large config objects)
- Eliminating unnecessary dependencies
- Checking value changes before state assignment in hot paths
- Using
LazyVStack/LazyHStackfor large lists - No object creation in view
body
Async Work
- Using
.taskfor automatic cancellation - Using
.task(id:)for value-dependent tasks - Not mixing
.onAppearwith async work
See reference files for detailed explanations of each item.
Constraints
- Swift/SwiftUI focus only - Exclude server-side Swift and UIKit unless bridging required
- No Swift concurrency patterns - Use
.taskfor SwiftUI async work - No architecture mandates - Don't require MVVM/MVC/VIPER or specific structures
- No formatting/linting rules - Focus on correctness and patterns
- No tool-specific guidance - No Xcode, Instruments, or IDE instructions
- Citations allowed:
developer.apple.com/documentation/swiftui/,developer.apple.com/documentation/swift/
All workflows must follow these constraints.
Philosophy
This skill focuses on facts and best practices from Apple's documentation:
- Modern APIs over deprecated ones
- Clear state ownership patterns
- Performance-conscious view composition
- Testable code structure
- No architectural mandates (MVVM/VIPER not required)
- Apple Human Interface Guidelines adherence
Reference Files
All references in references/:
workflows-review.md- Review methodology and findings taxonomyworkflows-refactor.md- Refactor methodology and invariantsrefactor-playbooks.md- Step-by-step refactor guidesstate.md- Property wrappers and ownership patternsnavigation.md- Navigation implementation patternsview-composition.md- View structure and extractionlists-collections.md- Identity and ForEach patternsscrolling.md- Scroll handling and paginationconcurrency.md- Async work with .taskperformance.md- Optimization strategiestesting-di.md- Testing and dependency injectionpatterns.md- Common SwiftUI patternsmodern-swiftui-apis.md- Legacy API migrationcode-review-refactoring.md- Code quality checks
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

