Skip to content

Instantly share code, notes, and snippets.

@kuotinyen
Last active December 21, 2018 09:46
Show Gist options
  • Save kuotinyen/ec78f8fc536947b924ae3f891b771041 to your computer and use it in GitHub Desktop.
Save kuotinyen/ec78f8fc536947b924ae3f891b771041 to your computer and use it in GitHub Desktop.
Transform notification event to RxSwift observable sequence.

Usage

NotificationCenter.default.rx
            .notification(custom: .gotFcmToken)
            .subscribe(onNext: { (value) in
                // do something
            })
            .disposed(by: bag)

Extension

extension Reactive where Base: NotificationCenter {
    func notification(custom name: Noti, object: AnyObject? = nil) -> Observable<Notification> {
        return notification(name.notificationName, object: object)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment