let notificationCenter: NotificationCenter = NotificationCenter.default
let notiName: Notification.Name = Notification.Name("noti날리자")
struct Receiver {
let name: String
let age: Int
init(name: String, age: Int) {
self.name = name
self.age = age
notificationCenter.addObserver(self, selector: #selector(receivedNotification), name: notiName, object: nil)
}
@objc func receivedNotification() {
print("I got a notification")
}
}
struct Sender {
func send() {
notificationCenter.post(name: notiName, object: nil)
}
}