Notification Center Posting Notification with User-Info

Viewed 99

For my code base, I have 3 functions and 3 dispatch groups (dg)

so when the 1st function is done, dg1's notify method is called and it calls func 2, and once that is done, dg2's notify method is called and func 3 is called once that is finished dg3's notify is called, I have my data and I use it for further processing.

All the above logic is in another file

I want to pass the data is of func 3, available in dg3's notify-execute method to my vc. I employed the notification center for this method. Using the following:

 let imageDataDict:[String: UIImage] = ["image": image]

  // post a notification
  NotificationCenter.default.post(name: NSNotification.Name(rawValue: "notificationName"), object: nil, userInfo: imageDataDict) 
  // `default` is now a property, not a method call

 // Register to receive notification in your class
 NotificationCenter.default.addObserver(self, selector: #selector(self.showSpinningWheel(_:)), name: NSNotification.Name(rawValue: "notificationName"), object: nil)

 // handle notification
 // For swift 4.0 and above put @objc attribute in front of function Definition  
 func showSpinningWheel(_ notification: NSNotification) {

  if let image = notification.userInfo?["image"] as? UIImage {
  // do something with your image   
  }
 }

However I never get the notification. How do I resolve this problem. I want to pass the data from the dispatch group elsewhere -in this case my VC.

0 Answers
Related