Question

I execute a fetch with this NSPredicate:

NSPredicate *sameNameAndNumber = [NSPredicate predicateWithFormat:@"name LIKE %@ AND number LIKE %@", field1, field2];

I get an exception:

2014-03-01 01:02:03.214 Memories[44692:3d03] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Can't do regex matching, reason: Can't open pattern U_REGEX_MISMATCHED_PAREN (string べきだ [べきだ], pattern まみれ (塗れ) [まにれ], case 0, canon 0)'

It looks like it's caused specifically by the string "まみれ (塗れ) [まにれ]". Regardless of the other string it's being compared to, I get the above exception.

If I replace LIKE in the above code with ==, I don't have this problem. Is the use of LIKE causing it to treat my test as regex? Does it not escape the parentheses and brackets in my string? How would I have it ignore the parentheses and brackets in my queries?

No correct solution

OTHER TIPS

You should use [NSPredicate predicateWithFormat:@"name Contains %@ AND number Contains %@", field1, field2] namely, use "Contains" to replace "Like" in Predicate.

If you use "Like" in a Predicate sentence, in case your field1 is equal to "(" - A Chinese left bracket, your app crashes. Then use "CONTAINS" to replace "LIKE".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top