views:

35

answers:

1

Following code works and deletes all calendar events from iPhone calendar database. But events are deleting very slow: 2 events per second on iPhone 3GS. So if you have 3000 events - then it's 25 minutes to erase them... How would you optimize this code? Maybe I am doing something wrong? Thanks.

- (void)deleteAllCalendarEventsFromIPhone:(NSError **)error {
    EKEventStore *store = [[EKEventStore alloc] init];

    NSUInteger beginYear = 1900;
    NSUInteger endYear = 2100;

    while (beginYear < endYear) {
        NSPredicate *predicate = 
            [store predicateForEventsWithStartDate:[self createDateWithYear:beginYear month:1 day:1] 
                                           endDate:[self createDateWithYear:beginYear + 4 month:1 day:1] 
                                         calendars:nil];
        NSArray *eventList = [store eventsMatchingPredicate:predicate];
        for (EKEvent *event in eventList) {         
            success = [store removeEvent:event span:EKSpanThisEvent error:nil];
        }
        beginYear += 4;
    }
    [store release];
}
A: 

Maybe because it is not the usage of EKEventStore !
Removing all user event is quite dangerous ...

Benoît
I disagree with you. It's the usage of EKEventStore. I receiving GroupWise calendars (5000 events) and saving it in iPhone calendar app (using prefix GW at the beginning of event name). And then, if user don't need these events in iCal - he can delete it, using my function.
arthur_skypro