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.
- 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
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.
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
- Huge thanks to this awesome video tutorial by Sean Allen