2009-03-02 121 views
0

我遇到了Cocoa中的核心數據模型問題。這可能是一個相當基本的問題。下面顯示了我的核心數據模型的一部分。給定OutputCell實體中單元屬性的值,我想返回相關的HistogramBar。使用NSPredicate遍歷多個核心數據對象

Share photos on twitter with Twitpic

我用下面的謂詞,但它只是返回一個空數組。我已經設法使用直方圖實體來處理它,但我似乎無法通過直方圖遍歷直方圖條到OuputCell。我使用的謂詞是:

NSEntityDescription *histogramBarEntityDescription = [NSEntityDescription entityForName:@"HistogramBar" 
                   inManagedObjectContext:[theDocument managedObjectContext]]; 
NSFetchRequest *histogramBarRequest = [[[NSFetchRequest alloc] init] autorelease]; 
[histogramBarRequest setEntity:histogramBarEntityDescription]; 
NSPredicate *histogramBarPredicate = [NSPredicate predicateWithFormat:@"(histogram.outputCell.cell = %@)", theOutputCell]; 
[histogramBarRequest setPredicate:histogramBarPredicate]; 
NSError *histogramBarError = nil; 
NSArray *histogramsArray = [[theDocument managedObjectContext] executeFetchRequest:histogramBarRequest 
    error:&histogramBarError]; 

Thankyou的幫助。

+0

你可以發佈多一點的代碼?我希望看到整個抓取請求。 – sbooth 2009-03-02 15:54:45

回答

2

我的問題已解決,代碼中的流氓評論阻止了HistogramBar實體的創建。在這種情況下,一些NSLog的詳細檢查有助於發現問題。