I am trying to filter Core Data
entities.
When trying to use or ||
logic operator in NSPredicate
, I get predicate parse error.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "(dRIV_NAMESURNAME CONTAINS[cd] %@) || (vEHI_PLATE CONTAINS[cd] %@)"'
When filtering with this, no problem:
NSPredicate* preFilter =
[NSPredicate predicateWithFormat:@"dRIV_NAMESURNAME CONTAINS[cd] %@", strSearch];
When filtering with this, no problem:
NSPredicate* preFilter =
[NSPredicate predicateWithFormat:@"vEHI_PLATE CONTAINS[cd] %@", strSearch];
This gives parse error:
NSPredicate* preFilter = [NSPredicate predicateWithFormat:
@"(dRIV_NAMESURNAME CONTAINS[cd] %@) || (vEHI_PLATE CONTAINS[cd] %@)",
strSearch, strSearch];
NSPredicate* preFilter = [NSPredicate predicateWithFormat:@"dRIV_NAMESURNAME CONTAINS[cd] %@ || vEHI_PLATE CONTAINS[cd] %@", strSearch, strSearch];
– Drmorgan||
should work in exactly the same way as the compound predicate. Can you verify that you are using the same data & search string (e.g. not anil
strSearch
)? – Mundi