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 c
Try this method
Create and Get Calendar
func getCalendar() -> EKCalendar? {
let defaults = UserDefaults.standard
if let id = defaults.string(forKey:"calendarID") {
return eventStore.calendar(withIdentifier: id)
} else {
let calendar = EKCalendar(for: .event, eventStore: eventStore)
calendar.title = "Calendar Title"
calendar.cgColor = UIColor.blue
calendar.source = self.eventStore.defaultCalendarForNewEvents!.source
do {
try eventStore.saveCalendar(calendar, commit: true)
defaults.set(calendar.calendarIdentifier, forKey: "calendarID")
print("Created calander")
} catch let error as NSError {
print("failed to Create calendar with error : \(error)")
}
return calendar
}
}