Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Provides `IObservable` semantics for `NSNotificationCenter` subscriptions
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