Skip to content

Instantly share code, notes, and snippets.

View bobleesj's full-sized avatar
💥
Excited!

Sangjoon Bob Lee bobleesj

💥
Excited!
View GitHub Profile
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(true)
NotificationCenter.default.removeObserver(self)
}
func catchNotification(notification:Notification) -> Void {
guard let name = notification.userInfo!["name"] else { return }
FirstVCLabel.text = "My name, \(name) has been passed! 😄"
}
NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: myNotificationKey),
object: nil,
queue: nil,
using:catchNotification)
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),
@IBAction func tabToNotifyBack(_ sender: UIButton) {
NotificationCenter.default.post(name: Notification.Name(rawValue: myNotificationKey), object: self)
secondVCLabel.text = "Notification Completed!😜"
}
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)
}