Created
July 23, 2014 23:13
-
-
Save jarek-foksa/09bb4db603e0bdeb9bb9 to your computer and use it in GitHub Desktop.
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
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