I am working on an iOS app which creates, updates, and deletes EKEvents
. This can easily be accomplish by saving the events to EKEventStore.defaultCalendarForNewEvents
. Under what circumstance would I want create a new EKCalendar
for my own app and what functionality does that entail?
I am asking because I am currently trying to create a calendar in Swift 3.0 and it keeps failing, which leaves me wandering what the purpose of the new calendar is in the first place.
fileprivate var eventStore = EKEventStore()
fileprivate var newCalendar : EKCalendar?
func createNewCalendar() {
self.newCalendar = EKCalendar(for: .event, eventStore: self.eventStore)
self.newCalendar!.title = "newCal"
let sourcesInEventStore = self.eventStore.sources
self.newCalendar!.source = eventStore.defaultCalendarForNewEvents.source
let newCalIndex = sourcesInEventStore.index {$0.title == "newCal"}
if newCalIndex == nil {
do {
try self.eventStore.saveCalendar(self.newCalendar!, commit: true)
print("cal succesful")
} catch {
print("cal failed")
}
}
}
I know i have access to the eventStore
because I can pull in events as well as save them to the EKEventStore.defaultCalendarForNewEvents
and update them using their existing calendar.