Esperando até que dois blocos assíncronos sejam executados antes de iniciar outro bloco
Ao usar o GCD, queremos aguardar até que dois blocos assíncronos sejam executados e executados antes de passar para as próximas etapas da execução. Qual o melhor jeito pra fazer isso?
Nós tentamos o seguinte, mas parece não funcionar:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
// block1
});
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
// block2
});
// wait until both the block1 and block2 are done before start block3
// how to do that?
dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^ {
// block3
});