本文介绍了NSPredicate在关系实体中进行搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为Band的实体,它与类别实体具有多对多关系。 Category实体只包含一个categoryName字符串属性。



示例记录:

 乐队:
bandName:Kiss
bandCategories: - > BandCategory:categoryName:Glam
- > BandCategory:categoryName:Rock

如何使用NSPredicate搜索所有我的乐队,

根据,您需要指定categoryName的关键路径,并使用 ANY ALL 说明符。

  NSString * category = @Rock 
[NSPredicate predicateWithFormat:@ANY bandCategories.categoryName ==%@,category];


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?

解决方案

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];

这篇关于NSPredicate在关系实体中进行搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 21:31