Why does my NSOperation subclass run the main method on the main thread? I want it to run asynchronously.
@interface ServiceClient : NSOperation
@end
@implementation ServiceClient
- (void)main
{
if ([[NSThread currentThread] isEqual:[NSThread mainThread]])
{
NSLog(@"Why does this get called on the main thread");
}
}
@end
Starting the operation
ServiceClient *serviceClient = [[ServiceClient aloc] init];
[serviceClient start];
EDIT:
Documentation suggest overriding isCuncurrent and returning yes, but the method does not get called.
- (BOOL)isConcurrent
{
return YES;
}
You need to set up your own thread in the
startmethodSnippet taken from Concurrency Programming Guide
If you add your
NSOperationto anNSOperationQueueit takes care of this for you.