agentleFS
harshii0509harshii0509/swift-skill-pack/skills/swift-patterns/SKILL.md

swift-patterns

Skill0 starsChanged 6 months agoMITView on GitHub

Apply production Swift architecture patterns for session-based dependency injection, Swift package modularization, UIKit and SwiftUI bridging, Combine-to-concurrency migration, and rendering performance. Use when structuring an iOS app, splitting modules, introducing dependencies, or cleaning up complex app architecture.

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. efremidze/swift-patterns-skill★ 10same 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 repository3 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    If the problem spans multiple architectural options, consult references/example-prompts.md before locking in a recommendation.

    line 27
  2. Very specific:

    If the question depends on precise iOS 26 SwiftUI UI-surface language, also consult ../swift/references/swiftui-vocabulary.md.

    line 28
  3. Distinctive:

    If the answer depends on distinguishing tab bar, bottom bar, safe-area bar, or bottom accessory, use the exact SwiftUI terms before …

    line 75
  4. Very specific:

    If a prompt says a bridge already behaves incorrectly, do not start with architecture redesign.

    line 86

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

You are a Swift architecture expert. Load the relevant reference files and give concrete, production-tested guidance.

Architecture Decision Guide

ProblemRecommended PatternReference
Shared mutable state across multiple viewsSession (@Observable class + .environment())references/session-architecture.md
Singleton everywhere, hard to testDependency injection via swift-dependenciesreferences/session-architecture.md
App growing past 50k lines, slow buildsSPM modularizationreferences/spm-modularization.md
Need UIKit component in SwiftUIUIViewRepresentablereferences/uikit-swiftui-bridge.md
UIKit app adding SwiftUI screensUIHostingControllerreferences/uikit-swiftui-bridge.md
Need mature UIKit/AppKit-backed SwiftUI controls fastSwiftUIX behind a local boundaryreferences/swiftuix-patterns.md
Combine publishers → async/awaitpublisher.values async sequencereferences/combine-to-async.md
60fps custom animation, Metal renderingCADisplayLink + TimelineViewreferences/rendering-performance.md
One codebase across iPhone, iPad, Mac, widgets, live activitiesFeature-rooted multiplatform compositionreferences/food-truck-patterns.md
Navigation state getting complex, deep links matterState-driven destinationsreferences/swift-navigation-patterns.md
Need Observation on older OS versionsBackported observation boundaryreferences/swift-perception-patterns.md

Topic Router

Reference files live in the sibling references/ folder for this skill. If the problem spans multiple architectural options, consult references/example-prompts.md before locking in a recommendation. If the question depends on precise iOS 26 SwiftUI UI-surface language, also consult ../swift/references/swiftui-vocabulary.md.

TopicFile
Session, DI, ViewModel, @Observable, environmentreferences/session-architecture.md
SPM, modularization, packages, build timesreferences/spm-modularization.md
UIViewRepresentable, UIHostingController, bridgereferences/uikit-swiftui-bridge.md
SwiftUIX, Cocoa views, missing SwiftUI controlsreferences/swiftuix-patterns.md
Combine, async/await, Publisher, sink, Taskreferences/combine-to-async.md
Metal, CADisplayLink, TimelineView, GPU, performancereferences/rendering-performance.md
Multiplatform, widgets, live activities, app surfacesreferences/food-truck-patterns.md
NavigationStack, NavigationSplitView, deep links, enum destinationsreferences/swift-navigation-patterns.md
Observation, backport, deployment target, WithPerceptionTrackingreferences/swift-perception-patterns.md

Which Pattern for Which Problem

MVVM vs Session

  • MVVM (ViewModel per screen): works for isolated screens with local state
  • Session: use when the same state is needed by 3+ screens, or when it persists across navigation (auth state, user profile, selected conversation)

ObservableObject vs @Observable (iOS 17+)

  • ObservableObject / @Published: use when you need iOS 16 support or are in a codebase already using Combine
  • @Observable (Observation framework): use for new code on iOS 17+; fine-grained dependency tracking, no manual @Published

Combine vs async/await

  • Combine: best for multi-publisher composition (combineLatest, merge, withLatestFrom)
  • async/await: best for sequential async work, error propagation, structured concurrency
  • Hybrid: expose AnyPublisher at the public interface, use async/await internally

SwiftUIX vs writing your own wrapper

  • SwiftUIX: use when the missing control is well-understood, reusable, and already maps cleanly to app needs
  • Custom representable: use when the behavior is app-specific, tightly scoped, or you need exact lifecycle control
  • Native SwiftUI: prefer when the platform now provides the feature and the bridge would only add dependency surface

Plain SwiftUI navigation vs Swift Navigation

  • Plain SwiftUI navigation: use when the flow is shallow and navigation state does not need to be modeled or restored explicitly
  • Swift Navigation: use when enum-driven destinations, deep linking, testable path state, or UIKit/AppKit parity matter

Observation vs Swift Perception

  • Native Observation: use for new code when your minimum OS already includes Apple's Observation framework
  • Swift Perception: use when you want the same mental model on older deployment targets or need a migration bridge without rewriting ownership boundaries twice

Bridge design vs bridge bug

  • Broken wrapper behavior: start in swift-debug
  • Wrapper or dependency choice: stay in swift-patterns

Modern surface vocabulary

  • If the answer depends on distinguishing tab bar, bottom bar, safe-area bar, or bottom accessory, use the exact SwiftUI terms before describing architecture consequences.

Correctness Rules (Non-Negotiable)

  1. Expose protocols, not implementations — every session/manager the rest of the app depends on must be a protocol so it can be mocked in tests.
  2. Never mutate @Observable state off the main thread — decorate the class with @MainActor or gate mutations through DispatchQueue.main.async.
  3. Use DependencyKey liveValue + testValue — every injectable dependency must have a mock so tests don't hit Firebase/network.
  4. Store AnyCancellable in a Set, not as a local var — a local AnyCancellable cancels immediately when it goes out of scope.
  5. Don't use weak self inside Task { } unless the task outlives the object — tasks created inside a class method capture self safely via structured concurrency.
  6. Hide third-party UI dependencies behind local adapters — app code should depend on your wrapper or feature view, not directly on a broad package everywhere.

If a prompt says a bridge already behaves incorrectly, do not start with architecture redesign. Hand the first pass to swift-debug, then return here only after the root cause is visible.

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.