Skip to content

josh-marasigan/ObserverDesignExample

Repository files navigation

An Observer Design Pattern Example

This repo consists of a simple iOS sample application for the Observer design pattern. Observers are notified of events via Notification and are registered via NotificationCenter.

Guide

  • This project was made for the purpose of explaining the main concepts within a simple Swift implementation of the Observer Pattern.
  • Please refer to the associated article to find out how it was made and why it was made the way it is.

Screenshots




Diagram

We’ll have a button (Subject) that will be notifying an Observer (an arbitrary view containing some labels) of it’s changes. In order for the view to receive notifications from this button, it will have to first subscribe to it.

To do this, we will be using the Notifications Framework to subscribe objects to one another and to send Notifications/events from one object to the other.

Dependencies

This sample app does require SnapKit for auto layout. So please install via cocoapod prior to building.

If you don't have cocoapods, run the following:

sudo gem install cocoapods

Then, change to the current project directory:

cd <YOUR PATH TO THE PROJECT DIRECTORY>/observer-example

(If you are unsure of where the directory is, look for the directory in which the Podfile resides and this is where you'll want to be)

Lastly run:

pod install

Credits:

About

An iOS sample application for the Observer design pattern

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published