What is the simplest approach to execute a Swift statement only after an asynchronous operation finishes?

For example,

  • Operation A both fetches model data over the network and updates a UICollectionViewbacked by it.
  • Operation B filters model data.

What is a good approach to executing B only after A is finished?

Usually it is to call operation B in completion handler of operation A.

You can also use Combine, which has various ways of dealing with your scenario - especially if the filtering also needs to be done asynchronously. I use Combine a lot with SwiftUI apps, because Combine’s Publishers can trigger a SwiftUI View’s .onReceive.

What is the simplest approach to execute a Swift statement only after an asynchronous operation finishes?
 
 
Q