如何返回所有当前事件?

时间:2013-10-19 21:14:36

标签: ios nsdate nsdatecomponents ekevent

我有一些我需要修改的示例代码,但我不知道如何继续。

// Fetch all events happening in the next 24 hours 
- (NSMutableArray *)fetchEvents
{
    NSDate *startDate = [NSDate date];

    //Create the end date components
    NSDateComponents *tomorrowDateComponents = [[NSDateComponents alloc] init];
    tomorrowDateComponents.day = 1;

    NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:tomorrowDateComponents
                                                                    toDate:startDate
                                                                   options:0];
    // We will only search the default calendar for our events
    NSArray *calendarArray = [NSArray arrayWithObject:self.defaultCalendar];

    // Create the predicate
    NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate
                                                                      endDate:endDate
                                                                    calendars:calendarArray];

    // Fetch all events that match the predicate
    NSMutableArray *events = [NSMutableArray arrayWithArray:[self.eventStore eventsMatchingPredicate:predicate]];

    return events;
}

我需要修改它以便它返回所有当前事件。也就是说,相对于当前时刻 - 过去发生的所有事件,将在过去开始并在将来结束。

这是我的第一个ios应用程序......有人能指出我正确的方向吗?

0 个答案:

没有答案