Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSPredicate to compare integer using Contains

I am using a NSPredicate to search numbers in the list using UISearchBar , it works in case of strings but does not work for an integer

I am using the following predicate

predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"%@ contains[c]  %d", @"number", [searchBar.text intValue]]];
[objectArray filterUsingPredicate:predicate];
[tableview reloadData];

FOR example if I type 1 then all the ones in the array must be listed, I have tried == it works only for the exact number if tried any work around for this any body?

Now I get an error if I use this method "Can't use in/contains operator with collection"

like image 805
raghul Avatar asked Aug 19 '12 03:08

raghul


1 Answers

I think this predicate should work for you:

predicate = [NSPredicate predicateWithFormat:@"self.number.stringValue CONTAINS %@",searchBar.text];

After thinking about this, I'm not sure why self.number.stringValue works, but it did when I tested it (self.number is an int). Not sure why I can send stringValue to an int?

like image 64
rdelmar Avatar answered Sep 30 '22 18:09

rdelmar