Swift Design Patterns for iOS
A design pattern is a reusable way to organize a recurring problem. In iOS development, the useful question is not “Which pattern can I add?” but “Which boundary is making this feature hard to change or test?” These lessons start with that boundary and show small, original Swift examples from app development.
This section covers all 23 classic Gang of Four patterns plus 15 Swift, iOS, and concurrency patterns from the broader eleev catalog. Examples use original app scenarios rather than the reference implementations. Each lesson explains the problem, the Swift design, how it fits into an iOS feature, and where the pattern becomes costly.
Creational patterns
These patterns control how app objects are made.
| Pattern | iOS example |
|---|---|
| Abstract Factory | Keep consumer and business checkout components together |
| Builder | Assemble a validated share payload |
| Factory Method | Let a checkout flow create its review screen |
| Prototype | Duplicate a dashboard preset with fresh IDs |
| Singleton | Own a process-wide session snapshot |
Structural patterns
These patterns organize boundaries and relationships between objects.
| Pattern | iOS example |
|---|---|
| Adapter | Bridge a callback image loader to async/await |
| Bridge | Vary reminder type and delivery channel independently |
| Composite | Traverse nested settings groups and rows |
| Decorator | Add caching around a product loader |
| Facade | Coordinate inventory, payment, and receipt creation |
| Flyweight | Share map marker styles across many annotations |
| Proxy | Guard direct photo-library access |
Behavioral patterns
These patterns organize decisions, actions, and communication.
| Pattern | iOS example |
|---|---|
| Chain of Responsibility | Run ordered checkout checks |
| Command | Execute and undo a checklist rename |
| Interpreter | Evaluate a saved task-filter expression |
| Iterator | Traverse photo selections across albums |
| Mediator | Coordinate search query, filters, and results |
| Memento | Restore a photo-editing draft |
| Observer | Update multiple views from account state |
| State | Control legal upload transitions |
| Strategy | Switch feed ordering policies |
| Template Method | Share a document export workflow |
| Visitor | Export different note blocks |
Swift and iOS patterns
These patterns are especially common at Swift and platform boundaries.
| Pattern | iOS example |
|---|---|
| Coordinator | Own a UIKit onboarding flow |
| Dependency Injection | Supply real and preview article repositories |
| Delegate | Return a picker selection to its owner |
| Type Erasure | Store heterogeneous card providers |
| Object Pool | Reuse bounded image-processing workers |
| Lazy Initialization | Build a search index on first use |
| Null Object | Disable analytics in previews without optional calls |
| Multicast Delegate | Notify several upload-status listeners |
| Marker | Mark an app route as requiring authentication |
| Data Access Object | Hide a persistence store behind task operations |
| Specification | Combine catalog eligibility rules |
| MVVM | Keep a SwiftUI order screen separate from loading logic |
| Weak Reference | Avoid retaining a UIKit callback owner |
Concurrency patterns
| Pattern | iOS example |
|---|---|
| Balking | Ignore duplicate image-import requests while one runs |
| Read Write Lock | Understand a cache with concurrent reads and exclusive writes |
A practical learning order
- Start with Dependency Injection, Strategy, and Adapter to see how to isolate change at a feature boundary.
- Read the creational patterns when construction code starts obscuring feature code.
- Use structural patterns to simplify integrations and tree-shaped data.
- Study behavioral patterns where app state, actions, and collaboration become harder to manage.
- Read Singleton and Object Pool with their lifetime and memory tradeoffs in mind.
These are design tools, not required layers. A switch, a plain initializer, or a function is often clearer when the feature has only one stable behavior.
Further reading
The Swift Design Patterns collection by eleev and Refactoring.Guru's Swift catalog provide broader background. The eleev repository also lists concurrency, architectural, language, and other specialized patterns; those are distinct from the 23 classic patterns covered here. The examples and iOS scenarios in this section were written for Swift Rivals.