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
- ahmed3elshaer/everything-claude-code-mobiletheir own version, first seen Jun 14, 2026
- efremidze/swift-patterns-skilltheir own version, first seen Feb 25, 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
- 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.
- swift-debugSkill
- swift-prototypeSkill
- swiftSkill
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
- Very specific: line 27
If the problem spans multiple architectural options, consult references/example-prompts.md before locking in a recommendation.
- Very specific: line 28
If the question depends on precise iOS 26 SwiftUI UI-surface language, also consult ../swift/references/swiftui-vocabulary.md.
- Distinctive: line 75
If the answer depends on distinguishing tab bar, bottom bar, safe-area bar, or bottom accessory, use the exact SwiftUI terms before …
- Very specific: line 86
If a prompt says a bridge already behaves incorrectly, do not start with architecture redesign.
≈ “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
You are a Swift architecture expert. Load the relevant reference files and give concrete, production-tested guidance.
Architecture Decision Guide
| Problem | Recommended Pattern | Reference |
| Shared mutable state across multiple views | Session (@Observable class + .environment()) | references/session-architecture.md |
| Singleton everywhere, hard to test | Dependency injection via swift-dependencies | references/session-architecture.md |
| App growing past 50k lines, slow builds | SPM modularization | references/spm-modularization.md |
| Need UIKit component in SwiftUI | UIViewRepresentable | references/uikit-swiftui-bridge.md |
| UIKit app adding SwiftUI screens | UIHostingController | references/uikit-swiftui-bridge.md |
| Need mature UIKit/AppKit-backed SwiftUI controls fast | SwiftUIX behind a local boundary | references/swiftuix-patterns.md |
| Combine publishers → async/await | publisher.values async sequence | references/combine-to-async.md |
| 60fps custom animation, Metal rendering | CADisplayLink + TimelineView | references/rendering-performance.md |
| One codebase across iPhone, iPad, Mac, widgets, live activities | Feature-rooted multiplatform composition | references/food-truck-patterns.md |
| Navigation state getting complex, deep links matter | State-driven destinations | references/swift-navigation-patterns.md |
| Need Observation on older OS versions | Backported observation boundary | references/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.
| Topic | File |
| Session, DI, ViewModel, @Observable, environment | references/session-architecture.md |
| SPM, modularization, packages, build times | references/spm-modularization.md |
| UIViewRepresentable, UIHostingController, bridge | references/uikit-swiftui-bridge.md |
| SwiftUIX, Cocoa views, missing SwiftUI controls | references/swiftuix-patterns.md |
| Combine, async/await, Publisher, sink, Task | references/combine-to-async.md |
| Metal, CADisplayLink, TimelineView, GPU, performance | references/rendering-performance.md |
| Multiplatform, widgets, live activities, app surfaces | references/food-truck-patterns.md |
| NavigationStack, NavigationSplitView, deep links, enum destinations | references/swift-navigation-patterns.md |
| Observation, backport, deployment target, WithPerceptionTracking | references/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
AnyPublisherat the public interface, useasync/awaitinternally
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)
- 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.
- Never mutate
@Observablestate off the main thread — decorate the class with@MainActoror gate mutations throughDispatchQueue.main.async. - Use
DependencyKeyliveValue + testValue — every injectable dependency must have a mock so tests don't hit Firebase/network. - Store
AnyCancellablein a Set, not as a local var — a localAnyCancellablecancels immediately when it goes out of scope. - Don't use
weak selfinsideTask { }unless the task outlives the object — tasks created inside a class method captureselfsafely via structured concurrency. - 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.
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.

