1

I've made a NSMutableArray for the EKCalendars that my application uses. On the first launch I import all the calendars from the EventStore but I exclude the Birthdays calendar and the default Calendar, leaving only the user created calendars. However the problem is if there is only Birthdays calendar and the default Calendar. Heres what i've got so far...

for (int i = 0; i < theEventStore.calendars.count; i++) 
    {
        EKCalendar *c = [theEventStore.calendars objectAtIndex:i];
        if (c.type != EKCalendarTypeBirthday && c.type != EKCalendarTypeSubscription) 
        {
            if (c.type == EKCalendarTypeLocal && [c.title isEqualToString:@"Calendar"])
            {
                NSLog(@"Removed Calendar: %@", c);
            }
            else
            {
                [self.calendarLst addObject:c];
                NSLog(@"Added Calendar: %@", c);
            }
        }
    }

I'm a little stumped. Any help would be appreciated.

Benjamin
  • 663
  • 8
  • 23
  • does your app crash ? what is the problem with that ? –  Dec 16 '11 at 14:26
  • if the only calendars are Birthday, Subscription or 'Calendar'. Then later when I try to use the array the app crashes. – Benjamin Dec 16 '11 at 14:30
  • nothing really critical here. I suspect the crash is due to something else. –  Dec 16 '11 at 14:38

1 Answers1

0

I've added this after the original for loop. This ensures that there is something in the array.

int count = self.calendarLst.count;
NSLog(@"Count: %i",count);

if (count == 0) 
{
    for (int i = 0; i < theEventStore.calendars.count; i++) 
    {
         EKCalendar *c = [theEventStore.calendars objectAtIndex:i];
         if (c.type == EKCalendarTypeLocal && [c.title isEqualToString:@"Calendar"]) 
             {
                 [self.calendarLst addObject:c];
                 NSLog(@"Added Calendar: %@", c);
             }
         }
     }
 }

The problem was not for loop it was the empty array.

Benjamin
  • 663
  • 8
  • 23
  • Hi sobox, is that default calendar never used, can it always be discarded? I'm running my iPhone in Dutch, so my calendar title is 'Agenda'. With that, determining which calendar to hide based on the title doesn't feel right. I've asked a question about this myself http://stackoverflow.com/questions/10530330/how-to-decide-whether-the-default-ekcalendar-calendar-can-be-hidden. Did you make any other findings regarding this? Cheers. – epologee May 10 '12 at 08:44