块是在新线程还是原始线程上运行?

mem*_*ons 1 iphone cocoa-touch objective-c objective-c-blocks

如果我有下面定义的方法,传递给方法的块("处理程序")是否在由NSOperationQueue?创建的新线程上调用?或者它被传递到它时所处的线程上调用methodWithCompletionHandler:

-(void)methodWithCompletionHandler:(void (^)(NSString *message))handler
{
   // Note: We are currently on thread #1. Calling handler(@"my message") here
   //       will run on thread #1.

    NSBlockOperation* someOp = [NSBlockOperation blockOperationWithBlock: ^{

   // do some stuff
   }];

   [someOp setCompletionBlock:^{
      // Note: Now someOp is completing, but it's in thread #2. Does calling the handler
      //       as below also run in thread #2 or thread #1?
      handler(@"Some message.");
   }];

   NSOperationQueue *queue = [NSOperationQueue new];
   [queue addOperation:someOp];
}
Run Code Online (Sandbox Code Playgroud)