Ahmad Naser Turnkey Ecosystem Ahmad Naser
October 19, 2019

NotificationCenter addObserver Swift

Published in the Ahmad Naser ecosystem. Estimated reading time: 1 minute.

import Foundation


class API
{
    static let shared = API()
    
    func selectCategory(userInfo : [String:Any]) {
        NotificationCenter.default.post(name: .didSelectCategory, object: self, userInfo: userInfo)
    }

}
import Foundation

extension Notification.Name {
static let didSelectCategory = Notification.Name("didSelectCategory")
}
 NotificationCenter.default.addObserver(self, selector: #selector(didSelectCategory(_:)), name: .didSelectCategory, object: API.shared)
    @objc func didSelectCategory(_ notification : Notification) {
        
        let data = notification.userInfo as! [String : Any]
        
        lblCategoryName.text = data["catName"]  as! String
        catID = data["catID"] as! Int
        
        print(catID)
        
    }
      let data : [String : Any] = [
                              "catName" : section.selectedRow()?.value ?? "Nothing is selected",
                              "catID" : 1
                          ]
                          API.shared.selectDays(userInfo: data)

Leave a Reply

Your email address will not be published. Required fields are marked *