Test 1
Example A
void exampleA() {
char a = 'A';
^{
printf("%c\n", a);
}();
}
1、always works ?
2、only works with ARC ?
3、only works without ARC ?
4、never works ?
Example B
void exampleB_addBlockToArray(NSMutableArray *array) {
char b = 'B';
[array addObject:^{
printf("%c\n", b);
}];
}
void exampleB() {
NSMutableArray *array = [NSMutableArray array];
exampleB_addBlockToArray(array);
void (^block)() = [array objectAtIndex:0];
block();
}
1、always works ?
2、only works with ARC ?
3、only works without ARC ?
4、never works ?
Example C
void exampleC_addBlockToArray(NSMutableArray *array) {
[array addObject:^{
printf("C\n");
}];
}
void exampleC() {
NSMutableArray *array = [NSMutableArray array];
exampleC_addBlockToArray(array);
void (^block)() = [array objectAtIndex:0];
block();
}
1、always works ?
2、only works with ARC ?
3、only works without ARC ?
4、never works ?
Example D
typedef void (^dBlock)();
dBlock exampleD_getBlock() {
char d = 'D';
return ^{
printf("%c\n", d);
};
}
void exampleD() {
exampleD_getBlock()();
}
1、always works ?
2、only works with ARC ?
3、only works without ARC ?
4、never works ?
Example E
typedef void (^eBlock)();
eBlock exampleE_getBlock() {
char e = 'E';
void (^block)() = ^{
printf("%c\n", e);
};
return block;
}
void exampleE() {
eBlock block = exampleE_getBlock();
block();
}
1、always works ?
2、only works with ARC ?
3、only works without ARC ?
4、never works ?
题目来自parse的博文 http://blog.parse.com