Created
March 27, 2018 07:38
-
-
Save serhii-londar/624d1efe644b09957df9b7926d99faee to your computer and use it in GitHub Desktop.
Notification Swift https://stackoverflow.com/a/42373808/3507433
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
public protocol NotificationName { | |
var name: Notification.Name { get } | |
} | |
public extension RawRepresentable where RawValue == String, Self: NotificationName { | |
public var name: Notification.Name { | |
get { | |
return Notification.Name(self.rawValue) | |
} | |
} | |
} | |
class MyClass { | |
enum Notifications: String, NotificationName { | |
case myNotification | |
} | |
} | |
NotificationCenter.default.post(name: Notifications.myNotification.name, object: nil) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment