Skip to content

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.

PatterniOS example
Abstract FactoryKeep consumer and business checkout components together
BuilderAssemble a validated share payload
Factory MethodLet a checkout flow create its review screen
PrototypeDuplicate a dashboard preset with fresh IDs
SingletonOwn a process-wide session snapshot

Structural patterns ​

These patterns organize boundaries and relationships between objects.

PatterniOS example
AdapterBridge a callback image loader to async/await
BridgeVary reminder type and delivery channel independently
CompositeTraverse nested settings groups and rows
DecoratorAdd caching around a product loader
FacadeCoordinate inventory, payment, and receipt creation
FlyweightShare map marker styles across many annotations
ProxyGuard direct photo-library access

Behavioral patterns ​

These patterns organize decisions, actions, and communication.

PatterniOS example
Chain of ResponsibilityRun ordered checkout checks
CommandExecute and undo a checklist rename
InterpreterEvaluate a saved task-filter expression
IteratorTraverse photo selections across albums
MediatorCoordinate search query, filters, and results
MementoRestore a photo-editing draft
ObserverUpdate multiple views from account state
StateControl legal upload transitions
StrategySwitch feed ordering policies
Template MethodShare a document export workflow
VisitorExport different note blocks

Swift and iOS patterns ​

These patterns are especially common at Swift and platform boundaries.

PatterniOS example
CoordinatorOwn a UIKit onboarding flow
Dependency InjectionSupply real and preview article repositories
DelegateReturn a picker selection to its owner
Type ErasureStore heterogeneous card providers
Object PoolReuse bounded image-processing workers
Lazy InitializationBuild a search index on first use
Null ObjectDisable analytics in previews without optional calls
Multicast DelegateNotify several upload-status listeners
MarkerMark an app route as requiring authentication
Data Access ObjectHide a persistence store behind task operations
SpecificationCombine catalog eligibility rules
MVVMKeep a SwiftUI order screen separate from loading logic
Weak ReferenceAvoid retaining a UIKit callback owner

Concurrency patterns ​

PatterniOS example
BalkingIgnore duplicate image-import requests while one runs
Read Write LockUnderstand a cache with concurrent reads and exclusive writes

A practical learning order ​

  1. Start with Dependency Injection, Strategy, and Adapter to see how to isolate change at a feature boundary.
  2. Read the creational patterns when construction code starts obscuring feature code.
  3. Use structural patterns to simplify integrations and tree-shaped data.
  4. Study behavioral patterns where app state, actions, and collaboration become harder to manage.
  5. 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.

Released under the MIT License.