Member-only story
In iOS programming, we all have come across the term KVO which is key-value observer and if you have worked in an MVVM project then you might have used libraries like RxSwift.
However, KVO and RxSwift both work on the same principles which is the observer design pattern and hence it is very important to understand what this design pattern is and how it works
The observer design pattern consists of two components
1. Subject
2. Observer
To understand what is a “Subject” and “Observer” I would like to give an example
When the traffic lights are red, we stop the vehicle and observe the lights and wait for it to turn green
Once the traffic lights turn green we accelerate the vehicle and proceed to our destination.
Here the observer are the people who are waiting for the signal to turn green, when the signal turns green they act accordingly.
The subject, in this case, is the traffic light because when it’s state changes i.e. the color of the traffic light the observers who are observing the state of the traffic light act…