Skip to content

Instantly share code, notes, and snippets.

@ohsc
Created January 24, 2014 08:47
Show Gist options
  • Save ohsc/8594090 to your computer and use it in GitHub Desktop.
Save ohsc/8594090 to your computer and use it in GitHub Desktop.
Test Block in loops
#import <Foundation/Foundation.h>
int main(int argc, char *argv[]) {
@autoreleasepool {
typedef void (^MyBlock)();
MyBlock blocks[12];
int i = 0;
for (; i<5; i++) {
blocks[i] = ^(){
NSLog(@"value: %d, addr: %p", i, &i);
};
NSLog(@"block addr: %p", blocks[i]);
}
for (; i<10; i++) {
blocks[i] = [[^(){
NSLog(@"value: %d, addr: %p", i, &i);
} copy] autorelease];
NSLog(@"block addr: %p", blocks[i]);
}
i++;
blocks[10] = ^(){
NSLog(@"value: %d, addr: %p", i, &i);
};
i++;
blocks[11] = ^(){
NSLog(@"value: %d, addr: %p", i, &i);
};
blocks[1]();
blocks[2]();
blocks[5]();
blocks[6]();
blocks[10]();
blocks[11]();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment