Using Xcode 4.2 and ARC, I wrote the following code before I had an understanding of how blocks need to be copied from stack to heap.
-(void) downloadWithBlock:(void (^)(void))callbackBlock; {
The code works, but I donβt trust it because I donβt understand it. In another section of code, I ran into application crashes when calling blocks that were saved in ivars without using -copy. This made me wonder if this section of code should be rewritten as follows:
-(void) downloadWithBlock:(void (^)(void))callbackBlock; { void(^heapBlock)(void) = [callbackBlock copy];
My only problem is to better understand how block pointers work. Is any of these sections of code acceptable? Does the compiler call the block in another block to insert the hidden Block_copy operation?
source share