Notification Center is not working in collectionView DidSelect in iOS Swift?

0
47

[ad_1]

I am trying to receive data from notification addObserve. But observer does not receive any data. Posting data from collectionView DidSelect and receiving from another UIViewController. it does not called.

Here is my code:

    public func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
    {
        let imageDataDict:[String: Any] = ["image": self.setTabDatahttps://stackoverflow.com/q/74335746]
        print("image dict index::::", imageDataDict)
        
        
        NotificationCenter.default.post(name: Notification.Name("dynamicIndex"), object: nil, userInfo: imageDataDict)
     }

Receiver end UIViewController I have added this code

Add this in ViewDidload

     NotificationCenter.default.addObserver(self, selector: #selector(self.dynamicViewIndex(notification:)), name: Notification.Name("dynamicIndex"), object: nil)

Notification center observer objc function

    @objc func dynamicViewIndex(notification: NSNotification) {
         // handling code

         print("dynamic index value observered", notification)



        if let dict = notification.userInfo as NSDictionary? {


            if let ValueID = dict["image"] as? UInt {

                print("UInt index val:::", ValueID)

                }

            }
        }

    }

Any help much appreciated please…

[ad_2]