Adding Observer

//ViewDidLoad NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: "Logout"), object: nil) NotificationCenter.default.addObserver(self, selector:#selector(self.functionName), name: NSNotification.Name(rawValue: "Logout"), object: nil) @objc func functionName(_ notification: NSNotification) { // if let newFilter = notification.object as? [Int] { //Your code //} } deinit { NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: "Logout"), object: nil) } //Usage NotificationCenter.default.post(name: Notification.Name(rawValue: "Logout"), object: nil) //Also you can send data in object parameter

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.