✨ZRNotify is a new way of dealing with Notification,more simpler and more convenient
observer notification
NotificationCenter.default.addObserver(self, selector: #selector(acceptNotify), name: NSNotification.Name(rawValue: "NotifyName"), object: nil)
func acceptNotify(notify: Notification) {
print(notify)
}
post notification
NotificationCenter.default.post(name: Notification.Name(rawValue: "NotifyName"), object: "hello")
ZRNotify().on("NotifyName", notify: { notify in
print(notify.object)
})
post notification
NotificationCenter.default.post(name: Notification.Name(rawValue: "NotifyName"), object: "hello")
Initialize ZRNotify
let notify = ZRNotify()
start observer
there are two ways to observer,you can use one of them according to the actual situation
way 01: Separate Observer
notify.on("ScheduleA", notify: { notify in
print(notify.object)
}).on("ScheduleB", notify: { notify in
print(notify.object)
})
way 02: Unified Observer
notify.ons(["ScheduleA", "ScheduleB"], notify: { notify in
print(notify.object)
})
post notification
NotificationCenter.default.post(name: Notification.Name(rawValue: "ScheduleA"), object: "hello A")
NotificationCenter.default.post(name: Notification.Name(rawValue: "ScheduleB"), object: "hello B")
pod 'ZRNotify', '~> 0.0.5'
ZRNotify is under MIT license. See the LICENSE file for more info.