我有对象,每个事件都有Movie
多关系,有
我需要创建 fetchedResultController 的属性,这些电影在具体的一天有事件events
date
- (NSFetchedResultsController *)fetchedResultsControllerForEntertainments:(Class)className date:(NSDate *)date
{
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass(className)];
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"yyyy/MM/dd";
NSDate *startDate = [dateFormatter dateFromString:[dateFormatter stringFromDate:date]];
NSDateComponents *oneDay = [NSDateComponents new];
oneDay.day = 1;
NSDate *endDate = [[NSCalendar currentCalendar] dateByAddingComponents:oneDay toDate:startDate options:0];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(events, $s, ($s.date >= %@ AND $s.date < %@)).@count > 0", startDate, endDate];
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"objectId" ascending:YES];
fetchRequest.sortDescriptors = @[sortDescriptor];
fetchRequest.fetchBatchSize = 20;
NSFetchedResultsController *fetchResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:nil];
return fetchResultsController;
}
我想创建一个谓词来返回我的电影,这些电影有当前日期的事件