OGeek|极客世界-中国程序员成长平台

标题: ios - 如何编写谓词来过滤字典数组? [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 04:23
标题: ios - 如何编写谓词来过滤字典数组?

我有字典数组,字典包含作为 NSString 的键和作为整数的值。我尝试了以下代码,但没有得到结果。

NSPredicate *objPredicate = [NSPredicate predicateWithFormat"%@ = %@", key, [NSNumber numberWithInt:value]];

NSArray  *filteredArray = [array filteredArrayUsingPredicatebjPredicate];



Best Answer-推荐答案


使用这个:

NSPredicate *objPredicate = [NSPredicate predicateWithFormat"self[%@] = %@", key, @(value)];

NSArray  *filteredArray = [array filteredArrayUsingPredicatebjPredicate];

关于ios - 如何编写谓词来过滤字典数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27687895/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4