为获取请求设置谓词



我使用core data,在函数中:

- (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];

最新更新