4
votes

I tried to use following predicate to search for events in the Calendar but i'm getting the following exception 'NSInvalidArgumentException', reason: 'predicate was not created with EKCalendarStore methods'


//[_sender objectAtIndex:0] is Name of the event and [_sender objectAtIndex:1] is location of the event

NSPredicate *prediction=[NSPredicate predicateWithFormat:@"(SELF contains[cd] %@)", [NSString stringWithFormat: @"%@%@",[_sender objectAtIndex:0],[_sender objectAtIndex:1]]];
NSArray*events=[eventStore eventsMatchingPredicate:prediction];
2

2 Answers

2
votes

I followed the EventKit Programming Guide and got the solution.

   NSPredicate *prediction=[eventStore predicateForEventsWithStartDate:statedate endDate:enddate calendars:[eventStore calendars]];
   NSArray*events=[eventStore eventsMatchingPredicate:prediction];
1
votes

Here is a Swift 4.0 implementation:

import EventKit

let eventStore = EKEventStore()
let datePredicate = eventStore.predicateForEvents(withStart: begin, 
    end: end,
    calendars: eventStore.calendars(for: .event))
let events = eventStore.events(matching: datePredicate)