Ios 预测多个条件无结果

Ios 预测多个条件无结果,ios,objective-c,Ios,Objective C,我正在使用NSPredicate筛选搜索栏中的数组。这是我的代码,它工作得很好 NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[cd] %@",searchText]; filteredArray = [NSMutableArray arrayWithArray:[storesArray filteredArrayUsingPredicate:predicate]]; 问题是我想添加

我正在使用NSPredicate筛选搜索栏中的数组。这是我的代码,它工作得很好

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[cd] %@",searchText];

filteredArray = [NSMutableArray arrayWithArray:[storesArray filteredArrayUsingPredicate:predicate]];
问题是我想添加第二个条件作为名称,即地址。我该怎么做?我已经试过了,但是没有一个谓词起作用

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.name contains[cd] %@",searchText];
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"SELF.address contains[cd] %@",searchText];


NSPredicate *fullPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[predicate, predicate1]];
filteredArray = [NSMutableArray arrayWithArray:[storesArray filteredArrayUsingPredicate:fullPredicate]];
您可以使用:


如果需要同时满足这两个条件,请使用
比较运算符。
NSPredicate *predicate = 
    [NSPredicate predicateWithFormat:@"SELF.name contains[cd] %@ OR SELF.address contains[cd] %@", searchText, searchText];