cocoa iphone core-data predicate one-to-many fetchrequest
-
20-09-2019 - |
Question
I have a set of data where one of the attributes (Firmware) is a one-to-many relationship.
If I want to get any records where the firmware id is 1 I can create a predicate using
@"(ANY Firmware.FID==1)"
Then I have another set of conditions that will refine the set even more using
(TopLevel==YES) AND (Parent>0)
How can I combine them or set it up so that first it filters the firmware then it filters the second condition? Ultimately I want all of the records where Firmware.FID=1 and TopLevel==YES and Parent>0.
Thanks, Howie
Solution
You should be able to use this predicate:
[NSPredicate predicateWithFormat:@"TopLevel == %@ AND Parent > %@ AND ANY Firmware.FID == %@",[NSNumber numberWithBool:YES],[NSNumber numberWithInteger:0],[NSNumber numberWithInteger:1]];
I moved the condition on "ANY Firmware.FID" last since it is the most complex and it can be avoided if one of the other conditions has already failed.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow