Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用搜索栏搜索CoreData中的NSSet属性_Ios_Search_Core Data_Uisearchbar_Nspredicate - Fatal编程技术网

Ios 使用搜索栏搜索CoreData中的NSSet属性

Ios 使用搜索栏搜索CoreData中的NSSet属性,ios,search,core-data,uisearchbar,nspredicate,Ios,Search,Core Data,Uisearchbar,Nspredicate,我有一个CoreData模型,其中有一个对象“bar”,它与实体“drink”有一对多的关系 实体饮料只有一个名为“name”的属性 现在,在我的应用程序中,我有一个表格视图,其中显示了所有的栏,并包含一个搜索栏 在这个搜索栏中,我希望能够搜索酒吧中可用的名称、位置和可能的饮料 我已经实现了如下名称和位置: NSPredicate *predicate = [NSPredicate predicateWithFormat:@"

我有一个CoreData模型,其中有一个对象“bar”,它与实体“drink”有一对多的关系

实体饮料只有一个名为“name”的属性

现在,在我的应用程序中,我有一个表格视图,其中显示了所有的栏,并包含一个搜索栏

在这个搜索栏中,我希望能够搜索酒吧中可用的名称位置和可能的饮料

我已经实现了如下名称和位置:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"
                                       name contains[cd] %@ OR
                       location.name_extern contains[cd] %@ OR 
                       location.name_intern contains[cd] %@", 
                            searchText, searchText, searchText];
现在我的问题是:如何在NSSet中搜索name属性

编辑:

更清楚地说,以下是重要的数据模型:

Bar

Attributes: 
name
location
drinks

Location

Attributes:
name_extern
name_intern

Drink:

Attributes:
name
我有一个
searchText
,需要检查以下4个位置是否匹配:

  • (酒吧名称)
  • 外部名称(酒吧的位置)
  • 实习生姓名(酒吧所在地)
  • (酒吧所有饮料的)名称

  • 像这样的方法应该会奏效:

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"
                                           name contains[cd] %@ OR
                           location.name_extern contains[cd] %@ OR 
                           location.name_intern contains[cd] %@ OR
                       ANY location.drinks.name contains[cd] %@", 
                                searchText, searchText, searchText, searchText];
    

    谢谢你的主意!但我想你误解了我的问题。我会重新编辑这个问题使它更清楚。我希望现在它更清楚。。我需要检查饮料的名称是否包含搜索文本。。所以我认为你的答案行不通。