0

I'm trying to create a very simple command line app that shows all my reminders in the command line but I'm simply not getting any reminders shown (yes I do have some).

import Foundation
import EventKit

let eventStore: EKEventStore = EKEventStore()
let defaultList: EKCalendar?
var hasAccess: Bool = false
var reminders: [EKReminder]?

eventStore.requestAccess(to: EKEntityType.reminder, completion: {(granted, error) in
      hasAccess = granted ? true : false
    })

print("Has access: \(hasAccess)")

defaultList = eventStore.defaultCalendarForNewReminders()
print("Default List: \(defaultList?.title ?? "NONE")")

let lists = eventStore.calendars(for: .reminder)
print(lists.map {$0.title})

eventStore.fetchReminders(matching: eventStore.predicateForReminders(in: nil)) { (_ rems: [EKReminder]?) -> Void in
  print(rems)
  reminders = rems
  }

print(reminders)

As you can see, this is very simply. I get my hasAccess successfully and my defaultList and my lists but not my reminders.

I think this is because the fetchReminders function takes a completion and so this is something to do with threads or callbacks or something but the requestAccess function also has a completion but that works.

Please help!

BerkoBob
  • 13
  • 4
  • 1
    You can use https://stackoverflow.com/questions/31944011/how-to-prevent-a-command-line-tool-from-exiting-before-asynchronous-operation-co to make your script run until the async call is complete – Larme Oct 21 '22 at 17:34

0 Answers0