How to update NSMenuItem while NSMenu is showing in macOS

Issue #213

Use Runloop

1
2
3
4
5
6
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [weak self] _ in
let date = Date()
self?.updateStopItem(seconds: finishDate.timeIntervalSince1970 - date.timeIntervalSince1970)
})

RunLoop.main.add(timer!, forMode: .common)

Use Dispatch

1
2
3
4
5
6
timer = Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { [weak self] _ in
let date = Date()
DispatchQueue.main.async {
self?.updateStopItem(seconds: finishDate.timeIntervalSince1970 - date.timeIntervalSince1970)
}
})

Comments