EKEventStore methods sometimes return fewer calendars or events than expected.
I allocate an EKEventStore and query it for calendars and events. I also register for various notifications, including EKEventStoreChangedNotification, and re-query the store when those notifications are observed.
I have 10 calendars of which 4 are Google calendars. The following call always returns all 10 when first queried and usually returns all 10 on subsequent queries:
NSArray *calendars = [_eventStore calendarsForEntityType:EKEntityTypeEvent];
However, sometimes it will return 6 or 7 calendars. The missing 3 or 4 calendars are always my Google calendars.
I have the same issue with the following call:
NSArray *events = [_eventStore eventsMatchingPredicate:predicate];
It always returns all events when first queried and usually returns all events on subsequent queries, but sometimes will return fewer than expected events for my Google calendars.
Some users of my app have also reported this issue to me so it is not unique to my calendars.
The only way to "fix" the issue is to either wait an indefinite amount of time, after which the above calls will again return the expected calendars and events, or to completely start over by re-allocating a new store. Of course, neither is a good solution.
What is happening? I think this is a bug in EKEventStore, but I can't write a good Radar since it happens intermittently and is thus impossible to reliably replicate. The code where this is happening is here: https://github.com/sfsam/Itsycal/blob/master/Itsycal/EventCenter.m