Reputation: 60923
I have 2 blocks for getting data from server. When 2 blocks start execute, I show a loading dialog then I will hide it when 2 blocks complete.
// Show loading dialog
// Block 1
[[DataCenter shareInstance] getGenresListWithCallback:^(id result, id error) {
}];
// Block 2
[[DataCenter shareInstance] getJobsListWithUserType:user.type callback:^(id result, id error){
}];
How can I detect when 2 blocks are executed completely?
Upvotes: 1
Views: 44
Reputation: 131418
There are various ways you could do this. Here's one:
Create an atomic integer property taskCount. As you add each fetch job, increment taskCount. In each completion block, decrement self.taskCount. When it reaches 0, you're done. Note that you need to submit all your jobs in one shot at the beginning or you run the risk that a subset of them will finish before you submit them all.
You could also submit all the jobs onto a GCD dispatch queue and use dispatch groups to detect when they all complete, but that would involve restructuring your code.
Upvotes: 1