why eventsMatchingPredicate returns nil?
- by OneZero
Here's my code:
NSString * calID = [[NSUserDefaults standardUserDefaults] objectForKey:@"calendarIdentifier"];
EKCalendar *cal = [eventStore calendarWithIdentifier:calID];
// If calendar exists
if(cal)
{
// Retrieve all existing events until today
NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:[NSDate distantPast] endDate:[NSDate date] calendars:@[cal]];
self.events = [eventStore eventsMatchingPredicate:predicate];
if(self.events==nil)
NSLog(@"nil events!");
}
The calendarItentifier is the variable that I stored when I created the calendar in my program, so it's not the case I'm adding events on the wrong calendar.
However, the code does not work to retrieve past events on the calendar, it simply returns nil to self.events. But I DID add events on the calendar. Can anything tell me if there's anything wrong with the code?