/ZRNotify

deal with notification in chain

Primary LanguageSwiftMIT LicenseMIT

ZRNotify

build Swift CocoaPods License Platform

✨ZRNotify is a new way of dealing with Notification,more simpler and more convenient

Bad Way

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 Way

ZRNotify().on("NotifyName", notify: { notify in  
   print(notify.object)
})

post notification

NotificationCenter.default.post(name: Notification.Name(rawValue: "NotifyName"), object: "hello")

Advanced Usage

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")

Installation

pod 'ZRNotify', '~> 0.0.5'

License

ZRNotify is under MIT license. See the LICENSE file for more info.