Steaphann
Steaphann

Reputation: 2777

Filtering an NSArray with NSPredicate

I have an NSArray that I would like to filter with a predicate. Here is what I have.

NSLog(@"text is %@",txtSearch.text);
NSPredicate *bPredicate =
[NSPredicate predicateWithFormat:@"SELF beginswith[c] '%@'",txtSearch.text];
arrSearchedPlayers =
[arrPlayers filteredArrayUsingPredicate:bPredicate];
NSLog(@"array after searched is %@",arrSearchedPlayers);

When I enter a text my array keeps empty. But when I try this predicate,

 NSPredicate *bPredicate =
    [NSPredicate predicateWithFormat:@"SELF beginswith[c] 's'"];

I got the right results.Anybody has an idea what the problem is?

Kind regards

Upvotes: 1

Views: 216

Answers (1)

Mark Kryzhanouski
Mark Kryzhanouski

Reputation: 7241

Remove extra quotes in predicate

[NSPredicate predicateWithFormat:@"SELF beginswith[c] %@",txtSearch.text];

Upvotes: 7

Related Questions