gpt4 book ai didi

objective-c - 从数组中获取值并计算

转载 作者:行者123 更新时间:2023-11-28 18:40:21 25 4
gpt4 key购买 nike

我有一个数组宽度这个值:

array: (
{
id = 1;
name = "Cursus Nibh Venenatis";
value = "875.24";
},
{
id = 2;
name = "Elit Fusce";
value = "254.02";
},
{
id = 3;
name = "Bibendum Ornare";
value = "123.42";
},
{
id = 4;
name = "Lorme Ipsim";
value = "586.24";
}
)

我需要做的是获取每个“值”并将其相加。我正在声明一个新数组来获取每个值:

self.valuesArray = [[NSArray alloc] init];

但是我该怎么做呢?感谢您的回答!

最佳答案

double sum = [[array valueForKeyPath:@"@sum.value"] doubleValue];

您可以阅读更多关于集合运算符的信息 here

关于objective-c - 从数组中获取值并计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11759046/

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