0

I need to do multiple request for a MKDirections (10) and I want to make faster my iOS7 App. After 10 calculateDirectionsWithCompletionHandler, I want to update user interface. I try with async calls with GCD.

My problem is that with GCD I don't understand how to wait the end of all calculateDirectionsWithCompletionHandler before to update user interface.

This is my code:

dispatch_group_t taskGroup =  dispatch_group_create();
dispatch_queue_t mainQueue =  dispatch_get_main_queue();

dispatch_group_async(taskGroup, mainQueue, ^{
    [directions1 calculateDirectionsWithCompletionHandler:
     ^(MKDirectionsResponse *response, NSError *error) {...}];
});

.........

dispatch_group_async(taskGroup, mainQueue, ^{
    [directions10 calculateDirectionsWithCompletionHandler:
     ^(MKDirectionsResponse *response, NSError *error) {...}];
});

/* Update UI */
dispatch_group_notify(taskGroup, mainQueue, ^{

    /* Do some processing here and UI Update */

});

The problem is that the UI is updated before of the end of all calculateDirectionsWithCompletionHandler!

Why? Which is the problem in my code?

Thank you for help.

Mehmet Emre Portakal
  • 1,774
  • 21
  • 37

0 Answers0