0

How can I do things when two asynchronous requests are finished ?

perform the asynchronous initRequest and asynchronous refreshHeader, they finished after I perform the requestEnd method.

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self initRequest];
    [self requestEnd];
}

- (void)initRequest{
    [GBCompanyRequest requestWithSuccess:^(EvaluationAverage *evaluationAverage) {

    } failure:^(NSString *message) {

    }];

    [self refreshHeader];
}

- (void)refreshHeader{
    [GBCompanyEvaluationRequest requestWithSuccess:^(EvaluationAverage *evaluationAverage) {

    } failure:^(NSString *message) {

    }];
}

- (void)requestEnd{
    NSLog(@"How can I do things when two asynchronous requests are finished");
}

@end
Nirav Kotecha
  • 2,493
  • 1
  • 12
  • 26
Sunny_Ken
  • 11
  • 4

1 Answers1

1

My suggestion is use dispatch_group_t

dispatch_group_t : Generally use for call/execute group of synchronously or asynchronously method/block and it will notify you after all the method/block execution are done.

For more information about how to use, you can read this Q/A.

Waiting until two async blocks are executed before starting another block

iPatel
  • 46,010
  • 16
  • 115
  • 137