why eventsMatchingPredicate returns nil?

Posted by OneZero on Stack Overflow See other posts from Stack Overflow or by OneZero
Published on 2013-11-06T21:45:09Z Indexed on 2013/11/06 21:53 UTC
Read the original article Hit count: 704

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about ios

Related posts about cocoa-touch