@@ -25,25 +25,25 @@ public protocol EventSource {
2525 /// Posts a new notification originating from the receiver.
2626 ///
2727 /// - parameter event: The name of the event to post.
28- func post( _ event: String )
28+ func post( _ event: NSNotification . Name )
2929
3030 /// Register an action to run when an event is triggered. Returns an observer handle you can use to cancel the action.
3131 ///
3232 /// - parameter notificationName: The notification name to listen for
3333 /// - parameter executionBlock: A block of code to run when the receiver "hears" the specified notification name
3434 @discardableResult
35- func on( event notificationName: String , run: @escaping ( ) -> Void ) -> AnyObject
35+ func on( event notificationName: NSNotification . Name , run: @escaping ( ) -> Void ) -> Any
3636
3737 /// Register an action to run when an event is triggered by the specified sender. Returns an observer handle you can use to cancel the action.
3838 ///
3939 /// - parameter notificationName: The notification name to listen for
4040 /// - parameter sender: The object from which to listen for the notification
4141 /// - parameter executionBlock: A block of code to run when the receiver "hears" the specified notification name
4242 @discardableResult
43- func on( event notificationName: String , from sender: AnyObject ? , run executionBlock: @escaping ( ) -> Void ) -> AnyObject
43+ func on( event notificationName: NSNotification . Name , from sender: Any ? , run executionBlock: @escaping ( ) -> Void ) -> Any
4444
4545 /// Cancel a previously registered action from an observer handle.
46- func cancel( _ observer: AnyObject )
46+ func cancel( _ observer: Any )
4747}
4848
4949/// This extension allows any NSObject to post and listen for events in the same way as C4 objects.
@@ -58,8 +58,8 @@ extension NSObject: EventSource {
5858 /// ````
5959 ///
6060 /// - parameter event: The notification name for the event
61- public func post( _ event: String ) {
62- NotificationCenter . default. post ( name: Notification . Name ( rawValue : event) , object: self )
61+ public func post( _ event: NSNotification . Name ) {
62+ NotificationCenter . default. post ( name: event, object: self )
6363 }
6464
6565 /// An action to run on receipt of a given event.
@@ -74,7 +74,7 @@ extension NSObject: EventSource {
7474 /// - parameter run: A block of code to run when the receiver "hears" the specified event name
7575 /// - returns: A token to use for cancelling the action.
7676 @discardableResult
77- public func on( event notificationName: String , run executionBlock: @escaping ( ) -> Void ) -> AnyObject {
77+ public func on( event notificationName: NSNotification . Name , run executionBlock: @escaping ( ) -> Void ) -> Any {
7878 return on ( event: notificationName, from: nil , run: executionBlock)
7979 }
8080
@@ -91,9 +91,9 @@ extension NSObject: EventSource {
9191 /// - parameter executionBlock: A block of code to run when the receiver "hears" the specified notification name
9292 /// - returns: A token to use for cancelling the action.
9393 @discardableResult
94- public func on( event notificationName: String , from sender: AnyObject ? , run executionBlock: @escaping ( ) -> Void ) -> AnyObject {
94+ public func on( event notificationName: NSNotification . Name , from sender: Any ? , run executionBlock: @escaping ( ) -> Void ) -> Any {
9595 let nc = NotificationCenter . default
96- let objectProtocol = nc. addObserver ( forName: NSNotification . Name ( rawValue : notificationName) , object: sender, queue: OperationQueue . current, using: { _ in
96+ let objectProtocol = nc. addObserver ( forName: notificationName, object: sender, queue: OperationQueue . current, using: { _ in
9797 executionBlock ( )
9898 } )
9999 return objectProtocol
@@ -106,7 +106,7 @@ extension NSObject: EventSource {
106106 /// ````
107107 ///
108108 /// - parameter token: A token returned from a call to `on(event:run:)` method
109- public func cancel( _ token: AnyObject ) {
109+ public func cancel( _ token: Any ) {
110110 let nc = NotificationCenter . default
111111 nc. removeObserver ( token)
112112 }
0 commit comments