0

I am trying to fetch events from a specific calendar only. On my iPhone I added a calendar "CalendarTest". What I want to do is in my app only fetch the events from that Calendar. I am doing the following.

self.defaultCalendar = [eventStore calendarWithIdentifier:@"CalendarTest"];
 NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
                 // asynchronous callback on the main thread
                 [events removeAllObjects];
                 NSLog(@"Fetching events from EventKit between %@ and %@ on a GCD-managed background thread...", fromDate, toDate);
                 dispatch_async(eventStoreQueue, ^{
                     NSDate *fetchProfilerStart = [NSDate date];
                     NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:fromDate endDate:toDate calendars:calendarArray];
                     NSArray *matchedEvents = [eventStore eventsMatchingPredicate:predicate];
                     dispatch_async(dispatch_get_main_queue(), ^{
                         NSLog(@"Fetched %d events in %f seconds", [matchedEvents count], -1.f * [fetchProfilerStart timeIntervalSinceNow]);
                         [events addObjectsFromArray:matchedEvents];
                         [delegate loadedDataSource:self];
                     });
                 });

But when I build and run I get the following error it crashes with the following error.

2012-11-20 11:45:35.445 CalendarApp[2685:1d03] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[0]'

Anybody has an idea? Kind regards!

Steaphann
  • 2,797
  • 6
  • 50
  • 109

0 Answers0