回调的简单使用,留一个笔记,方便以后查找
1,定义blocktypedefvoid(^signedRightJson)();
typedef void(^signedErrorJson)();
2,定义的中复制
-(void)performActionWithCompletion:(signedRightJson)completion{
completion();
}
3,调用
BlockDemo *bd= [[BlockDemoalloc]init];
[bd performActionWithCompletion:^{
NSLog(@"%@",d.price);
}];
完整代码:
typedef void(^signedRightJson)(); typedef void(^signedErrorJson)(); @interface BlockDemo : NSObject //定义方法 -(void)performActionWithCompletion:(signedRightJson) completion; @end #import "BlockDemo.h" @implementation BlockDemo -(void)performActionWithCompletion:(signedRightJson)completion{ completion(); } @end BlockDemo *bd= [[BlockDemo alloc]init]; [bd performActionWithCompletion:^{ NSLog(@"%@",d.price); }];