我怎样才能从完成块检索返回值?

是否有可能在主线程上运行完成块?

例如,我有一个方法返回一个值:

- (int)test { /* here one method is called with completion block with return type void */ [obj somemethodwithcompeltionblock: { /* here I am getting my Int which I want to return */ } ]; } 

但是由于完成块在后台线程上运行,我无法看到如何从完成块中返回整数值作为此方法的结果。

我怎样才能做到这一点?

你错过了关于块的asynchronous开发的一些基本知识。 除了它自己的范围之外,您不能从任何地方返callback度块。 将每个块视为自己的方法,而不是内联代码。

我觉得你要找的是类似于这个…

 - (void)testWithHandler:(void(^)(int result))handler { [obj somemethodwithcompeltionblock:^{ int someInt = 10; dispatch_async(dispatch_get_main_queue(), ^{ handler(10); }); } ]; } - (void)callSite { [self testWithHandler:^(int testResult){ NSLog(@"Result was %d", testResult); }]; }