Member-only story

The Chain of Responsibility Pattern in Swift

Pass a request along until someone handles it!

Steven Curtis
2 min readNov 19, 2022
Photo by Maria Lysenko on Unsplash

Difficulty: Beginner | Easy | Normal | Challenging

This article has been developed using Xcode 11.5 and Swift 5.2.4

The chain of responsibility is an OO version of if … else in a way that promotes the idea of loose coupling within your App.

Prerequisites:

Terminology:

Design Pattern: a general, reusable solution to a commonly occurring problem

Comparison with the decorator design pattern

The chain of responsibility pattern is very similar to the decorator pattern, but only one of the objects in the chain of responsibility.

First responder

Effectively you give multiple objects the opportunity to process a request. One great example of the Chain of Responsibility is the concept of responders.

UIKit starts with the first responder control that activated the keyboard, and then passes the call up the chain until a component can deal with the action.

--

--

Responses (1)