カレンダーイベントの外部変更に即時対応するためのイベント監視機構の追加

- EKEventStoreの変更通知を監視し、イベントやカレンダーの状態を自動で再読込する処理を追加
- 通知監視の開始・解除処理をコンストラクタおよびデイニシャライザで適切に実装
This commit is contained in:
2025-10-24 23:27:01 +09:00
parent 552a55ead6
commit f3a196c95d

View File

@@ -12,6 +12,27 @@ class CalendarService: ObservableObject {
Task {
await requestAccess()
}
setupNotificationObserver()
}
deinit {
NotificationCenter.default.removeObserver(self)
}
private func setupNotificationObserver() {
NotificationCenter.default.addObserver(
forName: .EKEventStoreChanged,
object: eventStore,
queue: .main
) { [weak self] _ in
self?.handleEventStoreChanged()
}
}
@MainActor
private func handleEventStoreChanged() {
loadCalendars()
loadEvents()
}
@MainActor