繁体   English   中英

使用NSPredicate过滤NSArray

[英]Filtering an NSArray with NSPredicate

我有一个NSArray,我想用谓词过滤。 这就是我所拥有的。

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

当我输入文本时,我的数组保持为空。 但是当我尝试这个谓词时,

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

我得到了正确的结果。有人知道问题出在哪里吗?

亲切的问候

删除谓词中多余的引号

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

暂无
暂无

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

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