我在EKEvents上遇到了抓取请求。
在Apple样本之后,我在20年前创建了两个日期,并在未来创建了20年。
NSDateComponents *twentyYearsAgoComponents = [[NSDateComponents alloc] init];
twentyYearsAgoComponents.year = -20;
NSDate *twentyYearsAgo = [[NSCalendar currentCalendar] dateByAddingComponents:twentyYearsAgoComponents
toDate:[NSDate date]
options:0];
// Create the end date components
NSDateComponents *twentyYearsFromNowComponents = [[NSDateComponents alloc] init];
twentyYearsFromNowComponents.year = 20;
NSDate *twentyYearsFromNow = [[NSCalendar currentCalendar] dateByAddingComponents:twentyYearsFromNowComponents
toDate:[NSDate date]
options:0];
NSPredicate *predicate = [self.eventStoreGD predicateForEventsWithStartDate:twentyYearsAgo endDate:twentyYearsFromNow calendars:@[self.calendarForEventGD]]; // nil = all calendars
NSLog(@"predicate : %@",predicate);
在控制台中,我打印了这个:
2015-04-10 14:52:52.825 ohmygoods[1658:270016] [dateFormatter stringFromDate:twentyYearsFromNow] : 2035-04-10
2015-04-10 14:53:06.120 ohmygoods[1658:270016] predicate : EKEventPredicate start:10/04/1995 14:51; end:10/04/1999 14:51; cals:(
"x-apple-eventkit:///Calendar/p11"
)
你看
end:10/04/1999 14:51
而不是10/04/2035 ???