Reputation: 1493
I have a NSArray & i am trying to filter results based on below mentioned Query :
self->filteredValues =
[self->AllValues filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF.sku contains[cd]%@",text]];
I am able to successfully filter results if i use SELF.sku or SELF.name separately.
Issue is when i use OR between the query like this ,i got the crash result:
self->filteredValues =
[self->AllValues filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(SELF.sku contains[cd]%@) OR (SELF.name contains[cd]%@)",text]];
Error : 2018-06-05 12:39:55.137706+0530 AppName[43371:14206450] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't look for value () in string (24" NOBLE WREATH (6)); value is not a string '
How to resolve this out.
Upvotes: 0
Views: 38
Reputation: 1180
Check the predicate's format string. You have two %@
placeholders but only one argument providing value.
I bet this will fix the issue:
[NSPredicate predicateWithFormat:@"(SELF.sku contains[cd]%@) OR (SELF.name contains[cd]%@)", text, text]
Upvotes: 1
Reputation: 8924
There second argument is missing in predicate.
self->filteredValues =
[self->AllValues filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"(SELF.sku contains[cd]%@) OR (SELF.name contains[cd]%@)",text, <#second argument#>]];
Set <#second argument#>
in predicate.
Upvotes: 1