Queue and handle multiple requests on iphone

In my application, I use the NSOperationQueue and NSInvocationOperation objects to do all the operations. I have several queues in my application, and I use KVO "isFinished", by calling of which I perform the following operation in the main thread.

The problem is that whenever I perform two operations one after another, my application displays a message:

*** 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 find out what is the best practice to perform the operations that are requested and perform them accordingly?

Thanx in advance.

+3
source share
1 answer

, . , :

1) [operation release], operation object KVO. `, . KVO.

2), , isEqualToString

3) , , , . :

operationQueue.maxConcurrentOperationCount = 1;

. , Grand Central Dispatch dispatch_sync .

0

Source: https://habr.com/ru/post/1762608/


All Articles