Skip to content

Instantly share code, notes, and snippets.

@kuotinyen
Last active December 21, 2018 09:47
Show Gist options
  • Save kuotinyen/6c40efa12ee8717b39c8c250497ae64e to your computer and use it in GitHub Desktop.
Save kuotinyen/6c40efa12ee8717b39c8c250497ae64e to your computer and use it in GitHub Desktop.
Add custom notification using enum way.

Usage

NotificationCenter.post(customeNotification: .gotFcmToken)

Extension

enum Noti: String {
    case gotFcmToken
    
    var stringValue: String {
        return "Noti" + rawValue
    }
    
    var notificationName: NSNotification.Name {
        return NSNotification.Name(stringValue)
    }
}

extension NotificationCenter {
    static func post(customeNotification name: Noti, object: Any? = nil){
        NotificationCenter.default.post(name: name.notificationName, object: object)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment