Note that there are some explanatory texts on larger screens.

plurals
  1. POPerform block inside a NSOperation
    primarykey
    data
    text
    <p>I have a method in some class which performs some task using a block. When I execute that method using NSInvocationOperation then control never goes to the block. I tried logging inside the block but that is never called actually. But if I simply call that method with instance of that class then everything works as expected.</p> <p>Don’t blocks run inside NSOperation?</p> <pre><code>NSInvocationOperation *op = [[NSInvocationOperation alloc] initWithTarget:myClassObj selector:@selector(myClassMethod:) object:obj1]; [[AppDelegate sharedOpQueue] addOperation:op]; [op release]; - (void)myClassMethod:(id)obj { AnotherClass *otherClass = [[AnotherClass allco] init] [otherClass fetchXMLWithCompletionHandler:^(WACloudURLRequest* request, xmlDocPtr doc, NSError* error) { if(error){ if([_delegate respondsToSelector:@selector(handleFail:)]){ [_delegate handleFail:error]; } return; } if([_delegate respondsToSelector:@selector(doSomeAction)]){ [_delegate doSomeAction]; } }]; } - (void) fetchXMLWithCompletionHandler:(WAFetchXMLHandler)block { _xmlBlock = [block copy]; [NSURLConnection connectionWithRequest:request delegate:self]; } -(void)connectionDidFinishLoading:(NSURLConnection *)connection { if(_xmlBlock) { const char *baseURL = NULL; const char *encoding = NULL; xmlDocPtr doc = xmlReadMemory([_data bytes], (int)[_data length], baseURL, encoding, (XML_PARSE_NOCDATA | XML_PARSE_NOBLANKS)); NSError* error = [WAXMLHelper checkForError:doc]; if(error){ _xmlBlock(self, nil, error); } else { _xmlBlock(self, doc, nil); } xmlFreeDoc(doc); } } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { if(_xmlBlock) { _xmlBlock(self, nil, error); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload