I am developing a test app in which I have an NSOperationQueue. I am creating an NSInvocationOperation and observing the "isFinished" property of that operation. Strangely the observeValueForKeyPath is called only sometimes. I am not able to understand the changes i have to make to get it called every time. Please help.
Here is the code i have written :
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
........//initialization
queue = [NSOperationQueue new];
operation=[NSInvocationOperation new];
operation = [[NSInvocationOperation alloc]initWithTarget:self selector:@selector(CreateOperationWithContext:) object:context];
[operation addObserver:self forKeyPath:@"isFinished" options:(NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld) context:NULL];
[queue addOperation:operation];
..... // launch the view controller
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([keyPath isEqualToString:@"isFinished"]) {
NSLog(@"came in");
[operation removeObserver:self forKeyPath:@"isFinished"];
}
else
{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}