我想取一串某种类型的记录,基于由用户定义的类型列表上...iPhone上的CoreData支持IN谓词吗?
[fetchRequest setEntity:[NSEntityDescription entityForName:@"myRecord" inManagedObjectContext:self.managedObjectContext]];
NSSet *shipTypes = [NSSet setWithObjects:[NSNumber numberWithInt:70],
[NSNumber numberWithInt:71],
[NSNumber numberWithInt:72],
[NSNumber numberWithInt:73],
[NSNumber numberWithInt:74],
nil];
NSPredicate *aPredicate = [NSPredicate predicateWithFormat:@"type in %@", shipTypes];
[fetchRequest setPredicate:aPredicate];
theRecords = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
...运行时,executeFetchRequest消息抛出一个异常...
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (type IN {71, 73, 70, 72, 74})'
我做错了什么,或者这真的不被支持?
这应该工作,但我不能为我的生活弄清楚为什么它不是。阅读Predicate Format String Syntax文档并查看是否可以找到任何内容:http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html – Tim 2009-09-16 23:56:23
同意。你可以尝试使用NSArray而不是NSSet,但应该按照书面方式工作。 – 2009-09-17 06:46:22
如果你得到它的工作,你应该标记其中一个答案是正确的。 – 2010-08-10 23:11:46