2

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:

enter image description here

I think this has to do something with multithreading, this is where I come from:

enter image description here

Xcode log:

enter image description here

Async-
  • 3,140
  • 4
  • 27
  • 49

1 Answers1

1

Ok, the issue with calendar was actually with the EventStore object that was created inside the for loop, each time during iteration, that's why accessing it gave weird behaviour. When created outside of the loop, and passed on to descending methods, it works.

Async-
  • 3,140
  • 4
  • 27
  • 49