I am creating a dummy data and call this method 200 times from a for loop:
func createEvent(eventStore: EKEventStore, title: String, startDate: NSDate, endDate: NSDate) {
let event = EKEvent(eventStore: eventStore)
event.title = title
event.startDate = startDate
event.endDate = endDate
event.calendar = eventStore.defaultCalendarForNewEvents
do {
try eventStore.saveEvent(event, span: .ThisEvent)
print("Adding event \(event.title)")
//savedEventId = event.eventIdentifier
} catch {
print("Bad things happened 1")
}
}
Some amount of events is properly made, but starting from around 90-100 - I hit error in catch "Bad things happened". When I set breakpoint there, I see EKErrorDomain "No calendar has been set", how can that be if some of the events is properly made, why is it inconsistent?
Xcode breakpoint moment:
I think this has to do something with multithreading, this is where I come from:
Xcode log: