2013-03-31 58 views
0

,並在功能:設置謂詞我使用的核心數據正在提取請求

- (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 *). 

當我運行代碼它不會返回任何東西!我如何編輯它使其工作?是否有任何最佳的解決方案來獲取具有相同關係值的對象?

回答

1

LIKE在謂詞中僅用於比較字符串。爲了獲取所涉及self.s所有對象,下面應該工作:

[NSPredicate predicateWithFormat:@"belongToS = %@", self.s]; 
+0

(假設'belongToS'是「一對一」的關係。) –