Search code examples
iosswiftremindersekeventstore

.calendarsForEntityType(EKEntityType.Reminder) not returning list of reminder lists


Help, trying to get a list of the reminder lists from EventKit. This just doesn't return anything. If I change EKEntityType.Reminder to .Event I get the calendars(Events) so I know the code is generally good.

Thoughts

var eventStore = EKEventStore()

func get_calendars(completed: (([EKCalendar])->())) {
   print("in Get_Calendars")

   let calendars = eventStore.calendarsForEntityType(EKEntityType.Reminder)

    for calendar in calendars as [EKCalendar] {
        // 2
        print(calendar.title)
        print(calendar.calendarIdentifier) 
    }
}

Solution

  • Two thoughts.

    1. Make sure you have requested access to the Reminders:

      let eventStore = EKEventStore()
      eventStore.requestAccessToEntityType(EKEntityType.Reminder, completion: {
          granted, error in
      
          if granted {
              let calendars = eventStore.calendarsForEntityType(.Reminder)
      
              for calendar in calendars as [EKCalendar] {
                  print(calendar.title)
                  print(calendar.calendarIdentifier)
              }
          }
          else {
              print("Permission denied by user")
          }
      })
      
    2. Make sure you have at least one reminder. If you are running in the simulator, you probably don't have any reminders, and you will not see a calendar. At least, that was what I saw while testing this.