Skip to content

Instantly share code, notes, and snippets.

@jarek-foksa
Created July 23, 2014 23:13
Show Gist options
  • Save jarek-foksa/09bb4db603e0bdeb9bb9 to your computer and use it in GitHub Desktop.
Save jarek-foksa/09bb4db603e0bdeb9bb9 to your computer and use it in GitHub Desktop.
import Foundation
class NotificationCenter {
func addObserver(name: String, object: AnyObject, callback: (NSDictionary) -> Void ) -> NSObjectProtocol {
var observer : NSObjectProtocol = NSNotificationCenter.defaultCenter().addObserverForName(name, object: object, queue: nil, usingBlock: {
(notification : NSNotification!) in
callback(notification.userInfo)
})
return observer
}
func addObserver(name: String, object: AnyObject, callback: Void -> Void ) -> NSObjectProtocol {
var observer : NSObjectProtocol = NSNotificationCenter.defaultCenter().addObserverForName(name, object: object, queue: nil, usingBlock: {
(notification : NSNotification!) in
callback()
})
return observer
}
func removeObserver(observer: NSObjectProtocol) {
NSNotificationCenter.defaultCenter().removeObserver(observer)
}
func postNotification(name: String, object: AnyObject, userInfo: NSDictionary) {
NSNotificationCenter.defaultCenter().postNotificationName(name, object: object, userInfo: userInfo)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment