【发布时间】:2015-02-13 08:44:20
【问题描述】:
我有 coreData 模型:
我正在尝试验证电影的时间表是否与电影和剧院相匹配,但我收到错误“此处不允许使用对多键”
这是我的代码:
NSManagedObjectContext *moc = [self managedObjectContext];
NSEntityDescription *timeDescription = [ NSEntityDescription entityForName:@"Schedules" inManagedObjectContext:moc];
NSPredicate *timePredicate = [NSPredicate predicateWithFormat:@"showTimes <= %@", _movieTime];
NSPredicate *moviePredicate = [NSPredicate predicateWithFormat:@"ANY movie.nameOfMovie CONTAINS[cd] %@", _movie];
NSPredicate *theatersPredicate = [NSPredicate predicateWithFormat:@"movie.theaters.nameOfTheater == %@", _theaterName];
NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[timePredicate,moviePredicate,theatersPredicate]];
NSFetchRequest *request = [NSFetchRequest new];
request.predicate = compoundPredicate;
request.entity = timeDescription;
NSError *error = nil;
NSArray *result = [moc executeFetchRequest:request error:&error];
如果我只使用以下谓词:
NSPredicate *timePredicate = [NSPredicate predicateWithFormat:@"showTimes <= %@", _movieTime];
NSPredicate *moviePredicate = [NSPredicate predicateWithFormat:@"ANY movie.nameOfMovie CONTAINS[cd] %@", _movie];
我可以匹配日程安排和电影,但我的问题是我如何才能匹配日程安排、电影和剧院,你们中的任何人都知道我做错了什么吗?
非常感谢您的帮助
【问题讨论】:
-
为什么你不只是在你的另一个问题中用 SUBQUERY 扩展我给你的答案的谓词?如果它工作正常,只需在时间中添加一个进一步的 AND 条件
-
有点重复?既然你遇到了同样的问题stackoverflow.com/questions/28436816/…?
-
@geo,我遇到的问题是当我的实体是“计划”到“剧院”时如何返回。 NSPredicate *theatersPredicate = [NSPredicate predicateWithFormat:@"movie.theaters.nameOfTheater == %@", _theaterName]; .
-
@Lame,这是完全不同的问题
标签: ios objective-c core-data nspredicate