Skip to content

Instantly share code, notes, and snippets.

@rdavisau
Created December 25, 2016 08:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdavisau/a72d84f4658ee5addfb690b1c69f1b8f to your computer and use it in GitHub Desktop.
Save rdavisau/a72d84f4658ee5addfb690b1c69f1b8f to your computer and use it in GitHub Desktop.
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