This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func viewDidDisappear(_ animated: Bool) { | |
| super.viewDidDisappear(true) | |
| NotificationCenter.default.removeObserver(self) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func catchNotification(notification:Notification) -> Void { | |
| guard let name = notification.userInfo!["name"] else { return } | |
| FirstVCLabel.text = "My name, \(name) has been passed! 😄" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: myNotificationKey), | |
| object: nil, | |
| queue: nil, | |
| using:catchNotification) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| class FirstVC: UIViewController { | |
| @IBOutlet weak var FirstVCLabel: UILabel! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| NotificationCenter.default.addObserver(self, | |
| selector: #selector(doSomethingAfterNotified), | |
| name: NSNotification.Name(rawValue: myNotificationKey), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @IBAction func tabToNotifyBack(_ sender: UIButton) { | |
| NotificationCenter.default.post(name: Notification.Name(rawValue: myNotificationKey), object: self) | |
| secondVCLabel.text = "Notification Completed!😜" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SecondVC: UIViewController { | |
| @IBOutlet weak var secondVCLabel: UILabel! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| NotificationCenter.default.addObserver(self, | |
| selector: #selector(doThisWhenNotify), | |
| name: NSNotification.Name(rawValue: myNotificationKey), | |
| object: nil) | |
| } |
NewerOlder