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