mirror of
https://github.com/samsonjs/AsyncMonitor.git
synced 2026-03-25 08:25:47 +00:00
26 lines
691 B
Swift
26 lines
691 B
Swift
import Foundation
|
|
@testable import AsyncMonitor
|
|
|
|
@MainActor class SimplestVersion {
|
|
let cancellable = NotificationCenter.default
|
|
.notifications(named: .NSCalendarDayChanged).map(\.name)
|
|
.monitor { _ in
|
|
print("The date is now \(Date.now)")
|
|
}
|
|
}
|
|
|
|
@MainActor class WithContext {
|
|
var cancellables = Set<AnyAsyncCancellable>()
|
|
|
|
init() {
|
|
NotificationCenter.default
|
|
.notifications(named: .NSCalendarDayChanged).map(\.name)
|
|
.monitor(context: self) { _self, _ in
|
|
_self.dayChanged()
|
|
}.store(in: &cancellables)
|
|
}
|
|
|
|
func dayChanged() {
|
|
print("The date is now \(Date.now)")
|
|
}
|
|
}
|