一、代码——命令行模式
//main.m
#import
struct__block_impl {void *isa;intFlags;intReserved;void *FuncPtr;
};struct__main_block_desc_0 {
size_t reserved;
size_t Block_size;
};struct__main_block_impl_0 {struct__block_impl impl;struct __main_block_desc_0*Desc;intage;
};int main(int argc, const char *argv[]) {
@autoreleasepool {//^{//NSLog(@"This is a block");//}();
int age = 10;void (^block)(int, int) = ^(int a, intb){
NSLog(@"This is a block:%d", age);
NSLog(@"a:%d b:%d", a, b);
};struct __main_block_impl_0 *blockStruct = (__bridge struct __main_block_impl_0 *)block;
block(20, 30);
}return 0;
}
分析:以下代码的前提,因为我们知道block底层的构造就是上述结构体的构造,桥接的目的就是展示这样的结构体内部是怎样的;
struct __main_block_impl_0 *blockStruct = (_