Created
December 25, 2016 08:01
-
-
Save rdavisau/a72d84f4658ee5addfb690b1c69f1b8f to your computer and use it in GitHub Desktop.
Provides `IObservable` semantics for `NSNotificationCenter` subscriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class NSNotificationCenterExtensions | |
{ | |
public static IObservable<NSNotification> ObserveNotification(this NSNotificationCenter notificationCenter, NSString notificationKey) => | |
Observable.Create<NSNotification>(obs => | |
{ | |
var nsObserver = notificationCenter.AddObserver(notificationKey, obs.OnNext); | |
return Disposable.Create(() => notificationCenter.RemoveObserver(nsObserver)); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment