From f3a196c95d78df6008bb6404229d62dc1ea553aa Mon Sep 17 00:00:00 2001 From: ssig33 Date: Fri, 24 Oct 2025 23:27:01 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=AB=E3=83=AC=E3=83=B3=E3=83=80=E3=83=BC?= =?UTF-8?q?=E3=82=A4=E3=83=99=E3=83=B3=E3=83=88=E3=81=AE=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E5=A4=89=E6=9B=B4=E3=81=AB=E5=8D=B3=E6=99=82=E5=AF=BE=E5=BF=9C?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81=E3=81=AE=E3=82=A4=E3=83=99?= =?UTF-8?q?=E3=83=B3=E3=83=88=E7=9B=A3=E8=A6=96=E6=A9=9F=E6=A7=8B=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - EKEventStoreの変更通知を監視し、イベントやカレンダーの状態を自動で再読込する処理を追加 - 通知監視の開始・解除処理をコンストラクタおよびデイニシャライザで適切に実装 --- Sources/CalendarService.swift | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Sources/CalendarService.swift b/Sources/CalendarService.swift index bddef8a..0f5cbf4 100644 --- a/Sources/CalendarService.swift +++ b/Sources/CalendarService.swift @@ -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