December 2018
Intermediate to advanced
414 pages
10h 19m
English
Dispatch groups let you organize tasks and execute a block when many tasks have completed. Let's suppose that we need to wait for many long-running tasks to complete, but we don't really know ahead of time how many tasks we need to run, so using a semaphore is not a good solution. For this particular problem, using DispatchGroup is one of the best-suited solutions:
/**Performs some work on any thread- parameter done: A block that will be called when the work is done- note: This method may not be thread safe*/func doWork(done: @escaping () -> ()) { /* complex implementation doing important things */}
Consider the previous function, which could be provided by a third-party SDK or your own API. It performs some work, and, at a later ...
Read now
Unlock full access