使用 NSPredicate 遍历多个 Core Data 对象
我在 Cocoa 中的核心数据模型上遇到问题。 这可能是一个相当基本的问题。 我的核心数据模型的一部分如下所示。 给定 OutputCell 实体中单元格属性的值,我想返回相关的 HistogramBar。
我正在使用以下谓词,但它只返回一个空数组。 我已经设法使用 Histogram 实体让它工作,但我似乎无法从 HistogramBar 穿过 Histogram 并到达 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];
谢谢您的帮助。
I am having a problem with a Core Data model in Cocoa. It's probably a fairly basic problem. A section of my Core Data model is shown below. Given the value of a cell property in the OutputCell entity, I want to return the relevant HistogramBar.
I'm using the following Predicate but it just returns an empty array. I've managed to get it working using the Histogram entity but I don't seem to be able to traverse from HistogramBar through Histogram and on to OuputCell. The predicate I'm using is:
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 for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的问题已解决,代码中的恶意注释阻止了 HistogramBar 实体的创建。 在本例中,对一些 NSLog 的详细检查有助于发现问题。
My problem is solved, a rogue comment in the code prevented the HistogramBar entities being created. In this instance detailed checking of some NSLog's helped spot the problem.