1234567891011121314151617181920212223242526272829303132333435363738 |
- //
- // NotificationExtension.swift
- // Inhealth
- //
- // Created by weclouds on 2019/12/24.
- // Copyright © 2019 weclouds. All rights reserved.
- //
- import Foundation
- protocol Notifier {
- associatedtype Notification:RawRepresentable
- }
- extension Notifier where Notification.RawValue == String{
- fileprivate static func name(for notification:Notification) -> String{
- return "\(self).\(notification.rawValue)"
- }
-
- func postNotification(_ notification:Notification,object:Any? = nil,userInfo:[String:Any]? = nil) {
-
- }
- static func postNotification(_ notification:Notification,object:Any? = nil,userInfo:[String:Any]? = nil){
- let aName = name(for: notification)
- NotificationCenter.default.post(name: Foundation.Notification.Name(aName), object: object, userInfo: userInfo)
- }
-
- static func addObserver(_ observer:Any,selector:Selector,notification:Notification,object:Any? = nil){
- let aName = name(for: notification)
- NotificationCenter.default.addObserver(observer, selector: selector, name: NSNotification.Name(aName), object: object)
- }
-
- static
- func removeObserver(_ observer: Any,notification:Notification,object:Any? = nil){
- let aName = name(for: notification)
- NotificationCenter.default.removeObserver(observer, name: NSNotification.Name(rawValue: aName), object: object)
- }
- }
|