Hi all,
In my application, I'm using NSOperationQueue and NSInvocationOperation objects to execute all the operations. I have multiple queues in my application and I am using KVO "isFinished" on call of which I am performing the next operation on main thread.
The problem is: whenever I perform two operations one after another my application crashes saying:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '<myViewController: 0x481b200>: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: isFinished
Observed object: <NSInvocationOperation: 0x45d9ea0>
Change: {
kind = 1;
}
Context: 0x0'
My general code is as follows:
operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(somemethod) object:nil];
[operation addObserver:self forKeyPath:@"isFinished" options:0 context:nil];
[operationQueue addOperation:operation];
[operation release];
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if([keyPath isEqual:@"isFinished"] && operation == object)
{
[operation removeObserver:self forKeyPath:@"isFinished"];
[self performSelectorOnMainThread:@selector(newerPostLoadingNumberOfUdates) withObject:nil waitUntilDone:YES];
}
else
{
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
I want to know wheather what is the best practice to enqueue operations that are requested and execute them accordingly?
Thanx in advance.