@implementation
-(void)doSomething:(void (^)(BOOL, int))completionBlock
{
NSLog(@"Do Something first");
completionBlock(YES, 1);
completionBlock(NO, 2);
NSLog(@"Then may be something else");
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self doSomething:^(BOOL isOk, int code) {
//code
}]
}
@end
헤더
typedef void (^responseBlock)(BOOL, int);
@implementation
-(void)doSomething:(responseBlock)completionBlock
{
NSLog(@"Do Something first");
completionBlock(YES, 1);
completionBlock(NO, 2);
NSLog(@"Then may be something else");
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self doSomething:^(BOOL isOk, int code) {
//code
}]
}
@end
참고출처
http://www.knowstack.com/objective-c-blocks-sample-code