How to keep track of list changes in reminders app, like Name or Color - Swift and SwiftUI App

167 Views Asked by At

I know there is the EKEventStoreChanged Event to keep track of changes in the Reminder-App. The only problem is that this event just get triggered, when a list in the reminder app gets created or deleted. Not edited.

Does anyone know how to keep track of editing changes, to update the SwiftUI View?

Thanks

The Observer I added so far:

NotificationCenter.default.addObserver(forName: .EKEventStoreChanged, object: ReminderManager.shared.eventStore, queue: nil) { notification in self.storeChanged(notification) }

1

There are 1 best solutions below

0
malhal On

In SwiftUI use onReceive for notifications, e.g.

 .onReceive(NotificationCenter.default.publisher(for: EKEventStoreChanged))
        { obj in

The docs state you should call refresh on the reminder and if it returns true, refetch it to get the changes and merge them into your edits. If it returns false it wasn't changed so you don't need to refetch it.

https://developer.apple.com/documentation/foundation/nsnotification/name/1507525-ekeventstorechanged

More info here

https://developer.apple.com/documentation/eventkit/updating_with_notifications

FYI there is a EKEventViewController that you could wrap in a UIViewControllerRepresentable, here is an example:

https://nemecek.be/blog/40/how-to-use-ekeventeditviewcontroller-in-swiftui#complete-code

(Note you will need to fix the Coordinator(self) mistake, self will go out of date the next time this struct is init.