Let's consider the following line of code:
reminder.calendar = appDelegate!.eventStore!.defaultCalendarForNewReminders()
this denotes that I put reminder into the default device's calendar. How can I create my own calendar from code?
The reason I want to create my own one is that I want to have possibility to manage all reminders there.
Create a new EKCalendar
instance for the specific type, assign a title and a source and save it to the database
let calendar = EKCalendar(for: .reminder, eventStore: eventStore)
calendar.title = "MyNewCalendar"
calendar.source = eventStore.defaultCalendarForNewReminders()?.source
do {
try eventStore.saveCalendar(calendar, commit: true)
} catch { print(error) }
Retrieving the reminder calendar is a bit tricky
var myCalendar: EKCalendar?
let calendars = eventStore.calendars(for: .reminder)
if let filteredCalendar = calendars.first(where: {$0.title == "MyNewCalendar"}) {
myCalendar = filteredCalendar
} else {
print("count not find reminder calendar 'MyNewCalendar'")
}