I am using NSPredicate for the performing Search as it does on iPhone when we search for any app.
I have say for example 4 keywords
I have tried creating a predicate with
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"keyword BEGINSWITH[c] 'd'"
It gives me Deccan as output.
But the problem is I want each word starting with d So from the above example I need output as
Deccan, New Delhi, Salaam Delhi but NOT Ahmedabad
Stucked in this issue from hours. tried contains, matches but my bad luck..
Any help towards right path will really be appreciated..
Thanks guys for your responses Here's what I come up with
NSString *matchString = [NSString stringWithFormat: @".*\\b%@.*",searchText];
NSString *predicateString = @"keyword MATCHES[c] %@";
NSPredicate *predicate =[NSPredicate predicateWithFormat: predicateString, matchString];
There are two way for you
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"keyword BEGINSWITH[c] 'd'"]
predicate = [NSPredicate predicateWithFormat:@"keyword BEGINSWITH[c] 'd'
OR keyword contains[c] ' d'"]
// i mean,'space+d'
So you'll it will satisfy both of possible cases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With