问题
I have an entity called Band which has a to-many relationship to a Category entity. The Category entity just contains a categoryName string attribute.
An example record:
Band:
bandName: Kiss
bandCategories: - > BandCategory:categoryName:Glam
- > BandCategory:categoryName:Rock
How would I use NSPredicate to search thru all my Bands for bands which match the Rock category, for example?
回答1:
According to the NSPredicate Programming Guide you will need to specify the key path to categoryName with the ANY
or ALL
specifier.
NSString *category = @"Rock";
[NSPredicate predicateWithFormat:@"ANY bandCategories.categoryName == %@", category];
来源:https://stackoverflow.com/questions/7064072/nspredicate-for-searching-within-relationship-entities