使用NSPredicate遍历多个Core Data对象
-
03-07-2019 - |
题
我在Cocoa中遇到Core Data模型的问题。这可能是一个相当基本的问题。我的核心数据模型的一部分如下所示。给定OutputCell实体中的单元属性的值,我想返回相关的HistogramBar。
我正在使用以下谓词,但它只返回一个空数组。我已经设法使用直方图实体使其工作,但我似乎无法从HistogramBar直方图遍历到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];
谢谢你的帮助。
解决方案
我的问题解决了,代码中的恶意评论阻止了HistogramBar实体的创建。在这种情况下,对一些NSLog的详细检查有助于发现问题。
不隶属于 StackOverflow