I have a have a number of calendars, which each have a number of events. I would like to find all the events for a calendar where date > x.
My method signature looks like this
-(NSArray*)eventsForCalender:(Calendar*)calender StartDate:(NSDate*)start endDate:(NSDate*)endDate;
I added an Event to a calender like this, but I don't have a clue how to go about to construct an NSPredicate for the query. Any help appreciated
-(Event*)newEventforCalender:(Calendar*)calender
{
Event * newEvent = (Event*)[NSEntityDescription insertNewObjectForEntityForName:@"Event" inManagedObjectContext:app.managedObjectContext];
NSMutableSet * eventsArray = [calender mutableSetValueForKey:@"Events"];
[eventsArray addObject:newEvent];
[app.managedObjectContext processPendingChanges];
return newEvent;
}
I changed the relationship name to "events" and tried the following
....
NSEntityDescription * entity = [NSEntityDescription entityForName:@"Calendar" inManagedObjectContext:app.managedObjectContext];
[request setEntity:entity];
NSPredicate * predictate = nil;
predictate = [NSPredicate predicateWithFormat:@"(name == %@) AND (Event.start > '%@') AND (Event.finish < '%@')", calender.name, start, endDate, nil];
[request setPredicate:predictate];
...
However i'm getting an exception
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ valueForUndefinedKey:]: this class is not key value coding-compliant for the key Event.'