gpt4 book ai didi

ios - 使用谓词过滤字典数组

转载 作者:行者123 更新时间:2023-11-29 10:43:11 25 4
gpt4 key购买 nike

我有以下字典数组:

Printing description of newOrderbookBids:
<__NSArrayI 0x10053e7c0>(
{
price = "10.14";
size = 148;
},
{
price = "10.134";
size = 0;
},
{
price = "10.131";
size = 321;
})

数组中的每个字典都有键pricesize,都是数字。

我想返回一个过滤后的数组,它只包含 size > 0 的字典。在此示例中,这将是包含字典 #1 和 #3 但没有字典 #2 的数组:

   ({
price = "10.14";
size = 148;
},
{
price = "10.131";
size = 321;
})

我已尝试使用以下代码片段按大小过滤我的 NSArray *newOrderbookBids:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"size > 0"];
newOrderbookBids = [newOrderbookBids filteredArrayUsingPredicate:predicate];

不幸的是,我的代码因运行时错误而崩溃

[NSSymbolicExpression compare:]: unrecognized selector sent to instance xxxx

我的代码和谓词有什么问题?如何按 size > 0 进行过滤?

谢谢!

最佳答案

“SIZE”是 "Predicate Format String Syntax" 中的保留关键字关键字不区分大小写。

要解决该问题,请使用“%K”格式参数作为 var arg 替换 a关键路径:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K > 0", @"size"];

关于ios - 使用谓词过滤字典数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23457801/

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