我正在尝试过滤Core Data
个实体。
在||
中尝试使用或NSPredicate
逻辑运算符时,我得到谓词解析错误。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(dRIV_NAMESURNAME CONTAINS[cd] %@) || (vEHI_PLATE CONTAINS[cd] %@)"'
使用此过滤时,没问题:
NSPredicate* preFilter =
[NSPredicate predicateWithFormat:@"dRIV_NAMESURNAME CONTAINS[cd] %@", strSearch];
使用此过滤时,没问题:
NSPredicate* preFilter =
[NSPredicate predicateWithFormat:@"vEHI_PLATE CONTAINS[cd] %@", strSearch];
这给出了解析错误:
NSPredicate* preFilter = [NSPredicate predicateWithFormat:
@"(dRIV_NAMESURNAME CONTAINS[cd] %@) || (vEHI_PLATE CONTAINS[cd] %@)",
strSearch, strSearch];
答案 0 :(得分:4)
您可以使用NSCompoundPredicate
之类的
NSPredicate* filter1 = [NSPredicate predicateWithFormat:@"dRIV_NAMESURNAME CONTAINS[cd] %@", strSearch];
NSPredicate* filter2 = [NSPredicate predicateWithFormat:@"vEHI_PLATE CONTAINS[cd] %@", strSearch];
NSArray *searchFilters=@[filter1,filter2];
NSPredicate *compoundPredicate=[NSCompoundPredicate orPredicateWithSubpredicates:searchFilters];