Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>After reading @Greg's commented link and this other Q: <a href="https://stackoverflow.com/questions/11909629/waiting-until-two-async-blocks-are-executed-before-starting-another-block">Waiting until two async blocks are executed before starting another block</a></p> <p>I came up with this which is working the way I want:</p> <pre><code>-(void)refreshView:(UIRefreshControl *)refresh { dispatch_group_t group = dispatch_group_create(); __block BOOL isReachable = NO; __block NSData *data = nil; __block NSData *dataPublic = nil; dispatch_group_async(group,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { isReachable = [self.appDelegate isReachable]; }); dispatch_group_wait(group, DISPATCH_TIME_FOREVER); dispatch_group_async(group,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { if (isReachable) { data = [self fetchNewData]; } }); dispatch_group_async(group,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { if (isReachable) { dataPublic = [self fetchPublicData]; } }); dispatch_group_notify(group,dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^ { if (isReachable) { dispatch_async(dispatch_get_main_queue(), ^{ //Public data if (dataPublic) { [self fetchedPublicData:dataPublic]; } else { //handle error } //User data if (data) { [self fetchedData:data]; [self.tableView reloadData]; } else { //handle error } [self.refreshControl endRefreshing]; }); } else { dispatch_async(dispatch_get_main_queue(), ^{ [self.refreshControl endRefreshing]; [self.appDelegate showConnectionErrorAlert]; }); } }); } </code></pre> <p>Please feel free to suggest improvements!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload