0

I can add a new calendar to the user's calendars like this, using the saveCalendar(_:commit:) method:

let ekStore = EKEventStore()

func saveCalendar(calendar: EKCalendar) throws {
    try ekStore.saveCalendar(calendar, commit: true)
}

and

let newList = EKCalendar(for: .reminder, eventStore: ekStore)

newList.source = ekStore.defaultCalendarForNewReminders()?.source
newList.title = newListName
newList.cgColor = listColor

do {

    try saveCalendar(calendar: newList)

} catch {

    print("Error adding list: \(error.localizedDescription)")

}

I then store the calendar object.

When the user finishes editing a calendar (reminders list) in my app, I try to save it like this, using the stored calendar as a starting point:

let updatedList = existingCalendar

updatedList.title = newListName
updatedList.cgColor = listColor

do {

    try saveCalendar(calendar: updatedList)

} catch {

    print("Error saving list: \(error.localizedDescription)")

}

But the calendar doesn't save and I get this error: That account does not support reminders.. I have also tried explicitly setting the calendar's source:

updatedList.source = ekStore.defaultCalendarForNewReminders()?.source

but then I get this error: That calendar may not be moved to another account..


My Question: How do I update calendars (reminder lists) from my app?

JustMakeStuff
  • 419
  • 3
  • 19
  • From the docs for `EKCalendar source`: *"This property can only be set for newly created calendar objects. This property is read-only after the first time it is set; setting a value to this property after the first time it is set will result in an error. Therefore, moving a calendar from one source to another is not supported."*. – HangarRash Dec 09 '22 at 03:50
  • @HangarRash Thanks. The `ekStore` object is initialized like this: `let ekStore = EKEventStore()` – JustMakeStuff Dec 09 '22 at 03:53
  • @HangarRash I am not trying to move the calendar to another source, just to update the title and color of the existing calendar object. – JustMakeStuff Dec 09 '22 at 03:58
  • The point of my quote from the docs is your attempt to set `source` during the update is not something you can do and it explains the error when you do try to set `source`. But it's not the reason for the error when you don't try to set `source` during the update. – HangarRash Dec 09 '22 at 03:59
  • @HangarRash Got it, thanks. `source` is a property of the `ekStore` object. See the updated question. – JustMakeStuff Dec 09 '22 at 04:02
  • It would probably help if you showed where `existingCalendar` comes from. The error seems to indicate you are loading the calendar from an account that doesn't actually support reminders which would seem to indicate it's not the same account used to create the calendar. – HangarRash Dec 09 '22 at 04:13
  • @HangarRash I loop through all the calendars with the `ekStore.calendars(for: EKEntityType.reminder)` method, and `existingCalendar` is the calendar that the user selected. – JustMakeStuff Dec 09 '22 at 15:49

0 Answers0