'Swift - notify collectionView from background thread and multiple views

I'm trying to notify a collectionView has changed from background. The background process is in first in first out (serial queue). The user can switch from one view to another, he is not necessarily in the view with the collectionView.

For example: I have 3 ViewControllers( vc )

  1. vc A hold the collectionView
  2. vc B which do some stuff
  3. vc C that add to the serial queue.

The process added to the queue can take 1-3 minutes, and the user doesn't have to wait until the end of process, he can go back or add more process in the queue. In the vc with the collection, each cell can have a loader if the item is in the background queue, I can call collection.reloadData on viewWilleAppear but

Issue : how to notify if the process ended while the user is already in vc A and trigger reloadData, or not if he's in vc B or vc C do nothing because viewWilleAppear will trigger it when he go to vc A

Class ControllerA : UIViewController {
   collectionView
}

Class ControllerB : UIViewController {
   //some stuff
}

Class ControllerC : UIViewController {
   func ... {
       let x = X()
       x.run();
   }
}

Class X {
   - static let queue
   func run() {
       X.queue.async {
           //long process
           Dispatch.main.asyn {
               // Todo reload collectionView if necessary
           }
       }
   }
}

Do you have any idea how to implement the notify ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source