Two concurrent background tasks need to patch two separate arrays which need to be merged in a dispatch_group_notify block.The problem is that.the first block is exceeded but the dispatch_group_notify is exceeded without waiting for the execution of the second background task. The only different between them is that the first one make a local search and the second one makes a remote call to a web service.Any clue why the second one is jumped over ?
Edit: I also tried the approach mentioned in https://stackoverflow.com/a/19580584/859742 using dispatch_barrier_async but still same.
 dispatch_group_t taskGroup = dispatch_group_create(); 
 dispatch_queue_t mainQueue = dispatch_get_main_queue();
__block NSArray *localAddresses;
__block NSArray *remoteAddresses;
//Get local array in the background 
dispatch_group_async(taskGroup, mainQueue, ^{
    //localAddresses  is set
});
//get remote array from server
dispatch_group_async(taskGroup, mainQueue, ^{
 [[MDAddressManager instance] searchForPlacesContainingText:query
                                                      location:alocation
                                                    completion:^(NSArray* addresses, MDError *error){
       //remoteAddresses is set
});
//Merge two arrays
dispatch_group_notify(taskGroup, mainQueue, ^{
   //remoteAddresses and local addresses are merged
});
And the remote search method looks like this
- (void)searchForPlacesContainingText:(NSString *)searchText
                         location:(CLLocation *)alocation
                       completion:(MDAddressManagerBlock)completionBlock
{
NSDictionary *parameters = [[NSMutableDictionary alloc] init];
[parameters setValue:searchText forKey:@"input"];
[[MDHTTPClient sharedHTTPClient] getPath:@"v1/remotePlaces.json"
                              parameters:parameters
                                 success:^(AFHTTPRequestOperation *operation, id dict) {
    if ([MDHTTPClient isResponseValid:dict])
    {
            completionBlock(returnArray, nil);
    }
    else
    {
            completionBlock(nil, nil);
    }
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    EDLog(@"%@", error);
    completionBlock(nil, [MDError errorAFNetworking:error]);
}];
}
 
     
    