xcode NSPredicate 'ALL 或 ANY 运算符的左侧必须是 NSArray 或 NSSet'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12127618/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NSPredicate 'The left hand side for an ALL or ANY operator must be either an NSArray or NSSet'
提问by Sean Danzeiser
Not totally sure why this isn't working now, i thought it had been working previously. Does anyone see an issue with this FetchRequest construction?
不完全确定为什么这现在不起作用,我认为它以前一直有效。有没有人看到这个 FetchRequest 结构有问题?
- (NSArray *)entriesForDate:(NSDate *)date {
NSFetchRequest *request = [[NSFetchRequest alloc]initWithEntityName:@"Entry"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY addedOn.unique like %@", [T3Utility identifierForDate:date]];
request.predicate = predicate;
NSError *error = nil;
NSArray *matches = [self.database.managedObjectContext executeFetchRequest:request error:&error];
return matches;
}
Again, i'm 99% sure that this code has been working until recently, so im thinking perhaps there's something else going on in my code somewhere . . .but when i run it through the debugger this is where is hangs. Here is my error:
再一次,我 99% 确定这段代码直到最近才有效,所以我想也许我的代码中某处发生了其他事情。. .but 当我通过调试器运行它时,这是挂起的地方。这是我的错误:
The left hand side for an ALL or ANY operator must be either an NSArray or NSSet
ALL 或 ANY 运算符的左侧必须是 NSArray 或 NSSet
Any ideas?
有任何想法吗?
thanks!
谢谢!
回答by Mundi
It seems addedOn
is not a to-many relationship. Make sure you use the correct names of your attributes / relationships in the predicate. Also, note that you cannot use a to-one relationship in a "ANY" predicate.
似乎addedOn
不是一对多的关系。确保在谓词中使用正确的属性/关系名称。另请注意,您不能在“ANY”谓词中使用一对一关系。