我有一些需要修改的示例代码,但我不确定如何继续。
// 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 应用程序...有人可以指出我正确的方向吗?