Skip to content

Commit

Permalink
MOD: <Comments>
Browse files Browse the repository at this point in the history
  • Loading branch information
RyukieSama committed Aug 4, 2022
1 parent 7a7b701 commit 2bf2cfb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
40 changes: 27 additions & 13 deletions Swifty/Classes/Foundation/Notification+Extension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,36 @@ public extension NotificationNameProtocol where Self.RawValue == String {
}

extension NotificationCenter {
/// 快速发送通知

/// Easy post notification with default NotificationCenter
/// - Parameters:
/// - notiString: 通知String
/// - anObject: 对象
/// - aUserInfo: UserInfo
public static func post(notification notiString: String, object anObject: Any? = nil, userInfo aUserInfo: [AnyHashable : Any]? = nil) {
NotificationCenter.default.post(name: Notification.Name(notiString), object: anObject, userInfo: aUserInfo)
/// - notiString: notiString
/// - object: object
/// - userInfo: userInfo
public static func post(notification notiString: String, object: Any? = nil, userInfo: [AnyHashable : Any]? = nil) {
NotificationCenter.default.post(name: Notification.Name(notiString), object: object, userInfo: userInfo)
}

/// 快速添加通知
/// Add observer for notification
/// - Parameters:
/// - observer: observer
/// - selector: selector
/// - notiString: notiString
/// - object: object
public static func addObserver(_ observer: Any, selector: Selector, notification notiString: String, object: Any? = nil) {
NotificationCenter.default.addObserver(observer, selector: selector, name: Notification.Name(rawValue: notiString), object: object)
}


/// Add observer for muti notification
/// - Parameters:
/// - observer: 观察者
/// - aSelector: selector
/// - notiString: 通知String
/// - anObject: 对象
public static func addObserver(_ observer: Any, selector aSelector: Selector, notification notiString: String, object anObject: Any? = nil) {
NotificationCenter.default.addObserver(observer, selector: aSelector, name: Notification.Name(rawValue: notiString), object: anObject)
/// - observer: observer
/// - aSelector: aSelector
/// - notiStrings: notifications
/// - anObject: anObject
public static func addObserver(_ observer: Any, selector aSelector: Selector, notifications notiStrings: [String], object anObject: Any? = nil) {
notiStrings.forEach {
NotificationCenter.default.addObserver(observer, selector: aSelector, name: Notification.Name(rawValue: $0), object: anObject)
}
}
}
3 changes: 1 addition & 2 deletions Swifty/Classes/Foundation/ThreadTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ class Debouncer {
fileprivate let semaphore: DispatchSemaphoreWrapper
fileprivate var workItem: DispatchWorkItem?


public init(label: String, interval: Float, qos: DispatchQoS = .userInteractive) {
self.interval = .milliseconds(Int(interval * 1000))
self.label = label
self.queue = DispatchQueue(label: "com.azizi.debouncer.internalqueue.\(label)", qos: qos)
self.queue = DispatchQueue(label: "com.swifty.debouncer.internalqueue.\(label)", qos: qos)
self.semaphore = DispatchSemaphoreWrapper(withValue: 1)
}

Expand Down

0 comments on commit 2bf2cfb

Please sign in to comment.