Observer Pattern in Swift

Jean-Marc Boullianne
1 min readNov 16, 2019

The Observer pattern is useful for when you need to maintain consistency between classes, while also maintaining their reusability. The two key terms to become familiar with in this pattern are subject and observer. A subject may have many observers dependent on it. When the subject changes state, all of the observers will be notified. Each observer will then query the subject for its value (or have it passed in the original notification), and then sync its state with the subject’s state.

This pattern can be useful for cases in which you need to update the user interface (UI) in response to changes in the model (data).

Swift Implementation

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response