Post a notification when a LogItem is added.

This commit is contained in:
Brent Simmons 2017-11-14 21:39:24 -08:00
parent 60ee139451
commit 887e562716
1 changed files with 11 additions and 0 deletions

View File

@ -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])
}
}