I'm trying to use Eventkit to access Mac Calendar.
Access is successfully requested but I keep getting nil or an empty array of calendar or events, even though I have several calendars and many eventsin local calendar, iCloud calendar, and Google calendar in the app.
The output I get from the following code is:
On My Mac
[]
[]
let sources = eventStore.sources
for source in sources{
print(source.title)
for calendar in source.calendars(for: .event){
print(calendar.title)
}
}
let calendars = eventStore.calendars(for: .event)
let predicate = self.eventStore.predicateForEvents(withStart: startDate, end: endDate, calendars: nil)
let events = self.eventStore.events(matching: predicate)
print(calendars)
print(events)
And if I try to create and save a calendar from code, then I'm getting error: Error Domain=EKErrorDomain Code=5 "Attempted to save when persistence was unavailable" UserInfo={NSLocalizedDescription=Attempted to save when persistence was unavailable}