Reputation: 487
Why does this predicate returns results:
predicate= [NSPredicate predicateWithFormat:@"itemsString like '*{4160366}*'"];
while this predicate returns empty array
predicate= [NSPredicate predicateWithFormat:@"itemsString like '*{%@}*'",[NSString stringWithString:@"4160366"]];
I's driving me crazy
Upvotes: 0
Views: 117
Reputation: 25740
When building a predicate, predicateWithFormat automatically adds quotes when performing variable substitution. So your (second) predicate ends up looking like this:
itemsString like '*{"4160366"}*'"
.
Notice the extra set of quotes.
Change it to:
predicate= [NSPredicate predicateWithFormat:@"itemsString like %@",[NSString stringWithFormat:@"*{%@}*", @"4160366"]];
and it should work.
(Note that instead of using stringWithString
I just used @""
which does the same thing.)
Upvotes: 1