Creating dispatch group
dispatch_group_t group = dispatch_group_create();
I am making 3 same api calls with dispatch wait
[self updateFrequency1];
dispatch_group_wait(group, 3.0);
[self updateFrequency2];
dispatch_group_wait(group, 3.0);
[self updateFrequency3];
dispatch_group_wait(group, 3.0);
Entering in dispatch group
-(void)updateFrequency1{
NSLog(@"updating frequency 1");
dispatch_group_enter(group);
[apimanager makeRequest];
}
-(void)updateFrequency2{
NSLog(@"updating frequency 2");
dispatch_group_enter(group);
[apimanager makeRequest];
}
-(void)updateFrequency3{
NSLog(@"updating frequency 3");
dispatch_group_enter(group);
[apimanager makeRequest];
}
Leaving dispatch group
-(void)responseReceived:(APIResponse*)response{
NSLog(@"leaving dispatch group");
dispatch_group_leave(group);
}
Console log with the above approach is
updating frequency 1
updating frequency 2
updating frequency 3
leaving dispatch group
leaving dispatch group
leaving dispatch group
Instead, I should get
updating frequency 1
leaving dispatch group
updating frequency 2
leaving dispatch group
updating frequency 3
leaving dispatch group