Created
August 12, 2023 23:17
-
-
Save mdb1/6836664853dd8ad6cd34d4762e019b2b to your computer and use it in GitHub Desktop.
Notification Center Poster protocol
This file contains 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
/// Reflects notification posting functionality of `NotificationCenter`. | |
public protocol NotificationPosterProtocol: AnyObject { | |
/// Creates a notification with a given name, sender and user info and posts it to the notification center. | |
/// - Parameters: | |
/// - aName: The name of the notification. | |
/// - anObject: The object posting the notification. | |
/// - userInfo: A user info dictionary with optional information about the notification. | |
func post(name aName: NSNotification.Name, object anObject: Any?, userInfo: [AnyHashable: Any]?) | |
/// Creates a notification with a given name and sender and posts it to the notification center. | |
/// - Parameters: | |
/// - aName: The name of the notification. | |
/// - anObject: The object posting the notification. | |
func post(name aName: NSNotification.Name, object anObject: Any?) | |
/// Creates a notification with a given name posts it to the notification center. | |
/// - Parameters: | |
/// - aName: The name of the notification. | |
func post(name aName: NSNotification.Name) | |
} | |
public extension NotificationPosterProtocol { | |
/// Creates a notification with a given name and sender and posts it to the notification center. | |
/// - Parameters: | |
/// - aName: The name of the notification. | |
/// - anObject: The object posting the notification. | |
func post(name aName: NSNotification.Name, userInfo: [AnyHashable: Any]?) { | |
post(name: aName, object: nil, userInfo: userInfo) | |
} | |
/// Creates a notification with a given name posts it to the notification center. | |
/// - Parameters: | |
/// - aName: The name of the notification. | |
func post(name aName: NSNotification.Name) { | |
post(name: aName, object: nil) | |
} | |
} | |
extension NotificationCenter: NotificationPosterProtocol {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment