iOSコールバック
1288 ワード
コールバックの簡単な使用は、メモを残して、後で検索するのに便利です.
1,blocktypedefvoid(^signedRightJson)();
typedef void(^signedErrorJson)();
2、定義中コピー
-(void)performActionWithCompletion:(signedRightJson)completion{
completion();
}
3、呼び出し
BlockDemo *bd= [[BlockDemoalloc]init];
[bd performActionWithCompletion:^{
NSLog(@"%@",d.price);
}];
完全なコード:
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);
}];