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];
}