I can provide a better answer if I know a little more about the code involved, but this should be easy. I will assume that the observer is a view controller, but this is the most straightforward way of setting this up.
- (void)viewWillAppear:(BOOL)animated
{
// …
[[Site singleton] addObserver:self forKeyPath:@"value" options:0 context:NULL];
[[Site singleton] addObserver:self forKeyPath:@"value.valves" options:0 context:NULL];
}
- (void)viewWillDisappear:(BOOL)animated
{
// …
[[Site singleton] removeObserver:self forKeyPath:@"value"];
[[Site singleton] removeObserver:self forKeyPath:@"value.valves"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if ([keyPath isEqualToString:@"value"]) {
// …
} else if ([keyPath isEqualToString:@"value.valves"]) {
// …
}
}
See Key-Value Coding Fundamentals.
Words of advice for KVO
Observe something that you know the full lifecycle of. A singleton is a good choice as long as it truly lives the whole life of the application. Generally, I stick to objects observing themselves.
Add an observer right when you need to do observing, remove an observer as soon as you no longer need observing. Always adding an observer in
-init*
and removing it in-dealloc
is asking for trouble.