gpt4 book ai didi

iphone - 使用NSPredicate过滤NSArray

转载 作者:行者123 更新时间:2023-12-01 17:32:40 25 4
gpt4 key购买 nike

我有一个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];

关于iphone - 使用NSPredicate过滤NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15243433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com