I am happy with the use of Key Value Observing (KVO), and how to register to receive notifications of property change:
[account addObserver:inspector
forKeyPath:@"openingBalance"
options:NSKeyValueObservingOptionNew
context:NULL];
However, if I want to observe changes in all the properties of the account object, how can I achieve this? Do I have to register for notification for each and every property?
It seems there's no built-in function to subscribe for changes in all properties of the objects.
If you don't care about which exactly property has changed and can change your class you can add dummy property to it to observe changes in other properties (using
+ keyPathsForValuesAffectingValueForKey
or+keyPathsForValuesAffecting<Key>
method):Now if you observe
dummy
property you'll get KVO notification each time any of object's properties is changed.Also you can get list of all properties in the object as in the code posted and subscribe for KVO notifications for each of them in a loop (so you don't have to hard code property values) - this way you'll get changed property name if you need it.