Created
January 24, 2014 08:47
-
-
Save ohsc/8594090 to your computer and use it in GitHub Desktop.
Test Block in loops
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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