AsyncMonitor/Tests/AsyncMonitorTests/ReadmeExamples.swift
2025-04-25 16:23:53 -07:00

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)")
}
}