If I have an object that uses KVO to observe a property on an object and then creates a partial layout for that observer, I no longer receive any notifications. Why is this?
Here's a minimal example:
@interface TestPartialMockAndKVO : SenTestCase @end @implementation TestPartialMockAndKVO - (void)test { // Should print "Changed!" when foo property is changed MyObserver* myObserver = [[[MyObserver alloc] init] autorelease]; // But with this line, there is no print out [OCMockObject partialMockForObject:myObserver]; [myObserver setFoo:@"change"]; } @end
-
@interface MyObserver : NSObject @property (copy) NSString* foo; @end @implementation MyObserver - (id)init { self = [super init]; [self addObserver:self forKeyPath:@"foo" options:0 context:NULL]; return self; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSLog(@"Changed!"); } - (void)dealloc { ... } @end
source share