Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KVO for a singleton with multiple observers?

I'm currently contemplating whether to use KVO or NSNotifications to alert several objects in my iOS app when a property of my singleton has changed.

Since all the objects that need to be notified of the change has a reference to the singleton, KVO would seem like the natural solution. However, I've never used KVO with a singleton and multiple observers, so I don't know if that pattern is advisable or even possible.

Is it a good idea (or even possible) to use KVO on a singleton with multiple observers?

like image 429
uvesten Avatar asked Jan 20 '26 19:01

uvesten


2 Answers

Use NSNotifications when you can wait for the event loop.

Use KVO when you need immediate response to the change in state.

like image 76
NSResponder Avatar answered Jan 23 '26 07:01

NSResponder


Use KVO in this is feasible, as the underlying Cocoa Framework has support built-in to notify the observers and you need not re-invent the wheel

like image 41
Bharath Booshan Avatar answered Jan 23 '26 09:01

Bharath Booshan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!