-2

There are two asynchronous tasks, and I don't know which of the two will be the last to finish. I want to do additional work after all the asynchronous tasks are completed, so how do you know that all asynchronous tasks have been completed?

Seul
  • 47
  • 3
  • Maybe you can checkout out Operation Queues and DispatchGroup. Here is a nice example of DispatchGroup - https://www.youtube.com/watch?v=6rJN_ECd1XM&ab_channel=LetsBuildThatApp – Shawn Frank Mar 15 '22 at 06:14
  • Those are antiquated now. [TaskGroup](https://developer.apple.com/documentation/swift/taskgroup) is the replacement. –  Mar 15 '22 at 08:17
  • Antiquated is a bit strong! Superseded by the new Concurrency features, but still perfectly valid esp in a legacy code base. Even Apple hasn’t depreciated them yet. – flanker Mar 15 '22 at 08:32

1 Answers1

0

You can use completion handler. It is a useful feature that allows us to handle asynchronous actions whilst keeping the method call and the resultant code close together.

Example of fully downloading a file

Sebastian Fox
  • 1,324
  • 1
  • 10
  • 20