Post a notification when a LogItem is added.
This commit is contained in:
parent
60ee139451
commit
887e562716
|
@ -8,9 +8,16 @@
|
|||
|
||||
import Foundation
|
||||
|
||||
public extension Notification.Name {
|
||||
|
||||
public static let LogDidAddItem = NSNotification.Name("LogDidAddItem")
|
||||
}
|
||||
|
||||
public class Log {
|
||||
|
||||
public var logItems = [LogItem]()
|
||||
public static let logItemKey = "logItem" // userInfo key
|
||||
private let lock = NSLock()
|
||||
|
||||
public init() {
|
||||
// Satisfy compiler
|
||||
|
@ -18,6 +25,10 @@ public class Log {
|
|||
|
||||
public func add(_ logItem: LogItem) {
|
||||
|
||||
lock.lock()
|
||||
logItems += [logItem]
|
||||
lock.unlock()
|
||||
|
||||
NotificationCenter.default.post(name: .LogDidAddItem, object: self, userInfo: [Log.logItemKey: logItem])
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue