我正在使用核心数据并在函数中:
- (NSFetchedResultsController*)fetchedResultsController()
我想使用一个谓词,让 NSFetchRequest 返回具有给定关系值的托管对象。我试过这个:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"belongToS like[cd] %@", (S*)self.s];
[fetchRequest setPredicate:predicate];
Note:
- belongToS: relationship of type (S *)
- self.s is a managed object casted to type (S *) since it is of NSManagedObject and actually it's truly an object of type (S *).
当我运行代码时,它没有返回任何内容!我该如何编辑它才能使其正常工作?是否存在获取具有相同关系值的对象的最佳解决方案?
最佳答案
谓词中的
LIKE
仅用于比较字符串。要获取与 self.s
相关的所有对象,应执行以下操作:
[NSPredicate predicateWithFormat:@"belongToS = %@", self.s];
关于ios - 为获取请求设置谓词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15729999/