Traversing multiple Core Data objects using NSPredicate
-
03-07-2019 - |
Question
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.
Solution
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.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow