Music_Player3/MusicPlayer/MP/Common/Extension(扩展)/Notification.swift
Mr.zhou 96147c5e37 项目:Musicoo
版本:A面 1.0
构建:1.1
更新内容:对项目A面功能的实现,经测试确定各项功能无问题。
更新时间:2024年4月12日 11:20
上传状态:已上传App Connect
2024-04-12 11:19:58 +08:00

71 lines
2.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// Notification.swift
// MusicPlayer
//
// Created by Mr.Zhou on 2024/4/1.
//
import Foundation
///
protocol NotificationKey {
associatedtype Keys: RawRepresentable
}
///RawValue
extension NotificationKey where Keys.RawValue == String {
///
static func post(notificationName key:Keys, object:Any? = nil) {
let rawValue = key.rawValue
NotificationCenter.default.post(name: NSNotification.Name(rawValue), object: object)
}
///
static func add(observer: AnyObject, selector: Selector, notificationName key: Keys, object:Any? = nil) {
let rawValue = key.rawValue
NotificationCenter.default.addObserver(observer, selector: selector, name: NSNotification.Name(rawValue), object: object)
}
///
static func remove(observer: AnyObject, notificationName key: Keys, object:Any? = nil) {
let rawValue = key.rawValue
NotificationCenter.default.removeObserver(observer, name: NSNotification.Name(rawValue), object: object)
}
}
//MARK: -
extension NotificationCenter{
struct notificationKey:NotificationKey {
///
enum Keys:String {
///taBarItem
case switch_tabBarItem
///
case time_times
///
case volume_change
///
case play_music
///
case stop_music
///
case pause_music
///
case resume_music
///
case open_monitor
///
case stop_monitor
///
case new_choice
///
case creat_music
///
case null_music
///
case close_show
///
case display_show
///
case hidden_show
///
case rename_music
}
}
}