OK, here is the code.
NSObject* (^executableBlock)(void) = ^NSObject*() {
__block NSObject *refObj = nil;
[Utility performAction:^() {
if (conditionA)
refObj = fooA;
else
refObj = fooB;
};
return refObj;
};
NSObject *result = executableBlock(); // result is nil
After executing the executableBlock, the result is nil and performAction block didn't be executed immediately and returned my expected value.
I know performAction block is executed within another thread and using the shared nil pointer refObj. Refer to Working with Blocks.
Here is my through, if I use GCD to call the performAction block and wait for its finish, how to rewrite it? Thanks!