NSPredicate for searching within relationship entities

我的未来我决定 提交于 2019-11-29 06:37:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!