agentleFS
efremidzeefremidze/swift-patterns-skill/swift-patterns/SKILL.md

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

  • Other versions2 projects use a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 2

    1. ahmed3elshaer/everything-claude-code-mobile★ 66same name
    2. 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.

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
  1. Very specific:

    Check state management against property wrapper selection (see references/state.md)

    line 14
  2. Very specific:

    Verify view composition and extraction patterns (see references/view-composition.md)

    line 15
  3. Very specific:

    Check async work patterns with .task (see references/concurrency.md)

    line 18
  4. Very specific:

    Verify navigation implementation (see references/navigation.md)

    line 19
  5. Distinctive:

    Use Review Response Template (below)

    line 20
  6. Distinctive:

    Use Refactor Response Template (below)

    line 29
  7. Very specific:

    Use modern APIs only (see references/modern-swiftui-apis.md)

    line 34
  8. Very specific:

    Always mark @State as private (makes ownership explicit)

    line 71
  9. Very specific:

    Never use @State for passed values (accepts initial value only)

    line 72
  10. Very specific:

    Use @State with @Observable classes (not @StateObject)

    line 73
  11. Distinctive:

    Use this when reviewing SwiftUI code:

    line 93
  12. Very specific:

    No Swift concurrency patterns: - Use .task for SwiftUI async work

    line 142
  13. Very specific:

    No architecture mandates: - Don't require MVVM/MVC/VIPER or specific structures

    line 143
  14. Distinctive:

    No tool-specific guidance: - No Xcode, Instruments, or IDE instructions

    line 145
  15. Distinctive:

    All workflows must follow these constraints.

    line 148
  16. Distinctive:

    No architectural mandates (MVVM/VIPER not required)

    line 157
  17. Very specific:

    All references in references/:

    line 162

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

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:

  1. Scope - What was reviewed
  2. Findings - Grouped by severity with actionable statements
  3. Evidence - File paths or code locations
  4. Risks and tradeoffs - What could break or needs attention
  5. Next steps - What to fix first or verify

Refactor Response:

  1. Intent + scope - What is being changed and why
  2. Changes - Bulleted list with file paths
  3. Behavior preservation - What should remain unchanged
  4. Next steps - Tests or verification needed

Quick Reference: Property Wrapper Selection

WrapperUse WhenOwnership
@StateInternal view state (value type or @Observable class)View owns
@BindingChild needs to modify parent's stateParent owns
@BindableInjected @Observable object needing bindingsInjected
letRead-only value from parentInjected
var + .onChange()Read-only value needing reactive updatesInjected

Key rules:

  • Always mark @State as private (makes ownership explicit)
  • Never use @State for passed values (accepts initial value only)
  • Use @State with @Observable classes (not @StateObject)

See references/state.md for detailed guidance and tradeoffs.

Quick Reference: Modern API Replacements

DeprecatedModern AlternativeNotes
foregroundColor()foregroundStyle()Supports dynamic type
cornerRadius().clipShape(.rect(cornerRadius:))More flexible
NavigationViewNavigationStackType-safe navigation
tabItem()Tab APIiOS 18+
onTapGesture()ButtonUnless need location/count
onChange(of:) { value in }onChange(of:) { old, new in } or onChange(of:) { }Two or zero parameters
UIScreen.main.boundsGeometryReader or layout APIsAvoid hard-coded sizes

See references/modern-swiftui-apis.md for complete migration guide.

Review Checklist

Use this when reviewing SwiftUI code:

State Management

  • @State properties marked private
  • Passed values NOT declared as @State or @StateObject
  • @Binding only 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 NavigationStack instead of NavigationView
  • Using Button instead of onTapGesture when 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 body simple 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

  • ForEach uses stable identity (never .indices for dynamic data)
  • Constant number of views per ForEach element
  • No inline filtering in ForEach (prefilter and cache)
  • No AnyView in 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/LazyHStack for large lists
  • No object creation in view body

Async Work

  • Using .task for automatic cancellation
  • Using .task(id:) for value-dependent tasks
  • Not mixing .onAppear with 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 .task for 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 taxonomy
  • workflows-refactor.md - Refactor methodology and invariants
  • refactor-playbooks.md - Step-by-step refactor guides
  • state.md - Property wrappers and ownership patterns
  • navigation.md - Navigation implementation patterns
  • view-composition.md - View structure and extraction
  • lists-collections.md - Identity and ForEach patterns
  • scrolling.md - Scroll handling and pagination
  • concurrency.md - Async work with .task
  • performance.md - Optimization strategies
  • testing-di.md - Testing and dependency injection
  • patterns.md - Common SwiftUI patterns
  • modern-swiftui-apis.md - Legacy API migration
  • code-review-refactoring.md - Code quality checks

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.