explaingit

ochococo/design-patterns-in-swift

15,253SwiftAudience · developerComplexity · 1/5Setup · easy

TLDR

A cheat-sheet of all classic Gang of Four design patterns, Behavioral, Creational, and Structural, implemented as runnable Swift 5 examples you can open and run in Xcode Playground.

Mindmap

mindmap
  root((design-patterns-swift))
    Behavioral Patterns
      Observer Strategy
      Command Iterator
      Visitor Memento
    Creational Patterns
      Singleton Builder
      Factory Prototype
    Structural Patterns
      Adapter Decorator
      Facade Proxy
    How to Use
      Xcode Playground
      No install needed
    Audience
      iOS developers
      Interview prep
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Study all 23 Gang of Four design patterns with runnable Swift 5 examples in an interactive Xcode Playground.

USE CASE 2

Use as a quick reference when you recognize a software problem and want to see a concrete Swift implementation of the matching pattern.

USE CASE 3

Prepare for iOS developer interviews by reviewing Singleton, Observer, Factory, and other common patterns with working code.

Tech stack

SwiftXcode

Getting it running

Difficulty · easy Time to first run · 5min

In plain English

This repository is a cheat-sheet of design patterns implemented in Swift, the programming language used to build apps for Apple platforms. Design patterns are reusable solutions to common problems in object-oriented software, originally catalogued by a group of authors often referred to as the Gang of Four (a term the repo's topics include). The description and topics say the examples are written in Swift 5.0 and presented as a short cheat-sheet. The README organises the patterns into the three classic families: Behavioral, Creational, and Structural. Behavioral patterns cover how objects talk to each other and includes entries like Chain of Responsibility, Command, Interpreter, Iterator, Mediator, Memento, Observer, State, Strategy, Template Method, and Visitor. Creational patterns deal with how objects are made and includes Abstract Factory, Builder, Factory Method, Monostate, Prototype, and Singleton. Structural patterns describe how objects are composed and includes Adapter, Bridge, Composite, Decorator, Facade, Flyweight, Protection Proxy, and Virtual Proxy. Each entry gets a short description of what the pattern is for plus a self-contained Swift example showing one way to implement it, and the project ships everything as an Xcode Playground download so you can run the snippets interactively. You would use this repository as a learning resource or quick reference when you are studying design patterns, preparing for an interview, or trying to recognise a pattern that fits a problem you have in a Swift project. It is not a library you install, it is documentation and runnable example code. The full README is longer than what was provided.

Copy-paste prompts

Prompt 1
Show me how the Observer pattern is implemented in the design-patterns-in-swift repo and explain when I would use it in a real iOS app.
Prompt 2
I have a Swift project where I need to create objects without specifying their exact class. Which Creational pattern fits, and how does this repo implement it?
Prompt 3
Walk me through the Builder pattern Swift example from this cheat-sheet and suggest a real UIKit or SwiftUI scenario where I would use it instead of a plain initializer.
Prompt 4
How does the Strategy pattern look in Swift? Give me the example from this repo and a practical iOS use case where I would swap strategies at runtime.
Prompt 5
What is the difference between Decorator and Proxy in the Structural patterns section, and when would I choose one over the other in a Swift project?
Open on GitHub → Explain another repo

← ochococo on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.