KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have read many docs on KVO, but I'm still confused as to when to use it. In case objA wants to monitor a certain property of objB , like so: self.objB = [[ObjB alloc] init]; [self.objB addObserver:self forKeyPath:@"address" options:0 context:nil]; so if objB 's property changes, and it can only be changed by self , why not just do this: self.objB.property = @"newValue"; [self doSomethingBasedOnNewValueOfObjBnewProperty]; instead of - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if(keyPath == @"address") { [self doSomethingBasedOnNewValueOfObjBnewProperty]; } } It may be useful when used with a singleton, like self.objB = [ObjB sharedInstance] , where properties may be changed by other objects. Is this the only use case?
Tags (comma-separated)
Save Edits
Cancel