How to send a number and a String through a notification ...
let mynumber=1;
let mytext=\"mytext\";
NSNotificationCenter.defaultCenter().postNotificationName
Swift 4.0, I am passing single key:value, you can add multiple keys and values.
NotificationCenter.default.post(name:NSNotification.Name(rawValue: "updateLocation"), object: ["location":"India"])
Adding Observer and Method definition. You also need to remove observer.
NotificationCenter.default.addObserver(self, selector: #selector(getDataUpdate), name: NSNotification.Name(rawValue: "updateLocation"), object: nil)
@objc func getDataUpdate(notification: Notification) {
guard let object = notification.object as? [String:Any] else {
return
}
let location = object["location"] as? String
self.btnCityName.setTitle(location, for: .normal)
print(notification.description)
print(notification.object ?? "")
print(notification.userInfo ?? "")
}