A completion Handler in iOS takes a thread to asynchronously get it done. So it means that we can’t know an exact point which the tasks finish. For example, if we use a for loop to execute several tasks in the background, how could we know all the task are done?
In this case you can use dispatch_group.
- Create a dispatch group which graps all the tasks in a for loop with
- You point out a position which your code enters the dispatch group with
- You point out a position which your code leave the dispatch group with
- Lastly you can get a notification when all the tasks you assigned to a dispatch group is done with
If you want to see a concrete example for it, please refer this.