1, release new notice:
NotificationCenter.default.post (Name: nsnotification.name (rawValue: "Messagemaincount"), Object:nil, UserInfo : ["Count": "\ (count)"])
2, accept the new notice
NotificationCenter.default.addObserver (Self, selector: #selector (self.changebadgevalue (Notification:)), Name: Nsnotification.name (rawValue: "Messagemaincount"), Object:nil)
3. Set the listening method for receiving notifications
Func Changebadgevalue (notification:notification), Void {let name = Notification.name let userInfo = Notifi Cation.userinfo as! [String:any] Let Userinfodic = UserInfo as nsdictionary if name = = Nsnotification.name (rawValue: ' Messagemaincount ') {let badgevalue:string = Userinfodic.object (forkey: "Count") as! String self.messageVC.parent?. Tabbaritem.badgevalue = Badgevalue }}
4. Remove Notification Monitor
deinit{ NotificationCenter.default.removeObserver (self)}
The Notificationcenter of Swift learning