简体   繁体   English

使用NSPredicate过滤NSArray

[英]Filtering an NSArray with NSPredicate

I have an NSArray that I would like to filter with a predicate. 我有一个NSArray,我想用谓词过滤。 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 亲切的问候

删除谓词中多余的引号

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM