Putting blocks into NSArray ; these are objects. In fact, they inherit from NSObject .
However, you need to copy them. These blocks are created on the stack and need to be moved to the heap to get past the end of the current method. If you use ARC, this is easy:
NSArray *array = [NSArray arrayWithObjects:[^{NSLog(@"Block 1");} copy], ...
In MRR, you need to balance this copy value, so you have two unpleasant options: use temps or list the array immediately after creating it and send release all your members.
Submitting invoke , on the other hand, is not completely kosher because it is a private method. The only fully API compatible way to call a block is the syntax of the call function:
typedef GenericBlock dispatch_block_t; for( GenericBlock block in array ){ block(); }
source share