gpt4 book ai didi

IOS如何检查数组的值是否包含某个值并将其显示出来

转载 作者:行者123 更新时间:2023-11-29 01:30:54 27 4
gpt4 key购买 nike

当我在控制台中注销时,我有一个数组提要,其中包含一组值。在我的日志中看起来像这样。

最终提要:( { 你好=红色; }, { 你好=绿色; }, { 你好=蓝色; }, { 你好=蓝色; }, { 你好=蓝色;

但是,当我使用 for 循环来循环索引以检索“蓝色”的值并计算失败的“蓝色”数量时。

这是我的代码

 - (void)parserDidEndDocument:(NSXMLParser *)parser {

NSLog(@"Final Feed : %@",feeds);

int count = 0;
int i;
NSString *value;
for (i = 0; i < [feeds count]; i++) {
NSString *bookTitle = [feeds objectAtIndex:i];


if([[feeds objectAtIndex:i] isEqual: @"{hello = blue;}"]){


count++;


}
}
NSLog(@"Total Warning count is: %d",count);
}

现在的问题是如何循环包含值“blue”的数组名称提要并进行计数?

最佳答案

因为 feeds 是字典数组所以尝试下面的代码:

NSInteger count = 0;
for (NSDictionary *feed in feeds) {
if ([feed[@"hello"] isEqualToString:@"blue"]) {
count++;
}
}
NSLog(@"%ld", (long)count);

关于IOS如何检查数组的值是否包含某个值并将其显示出来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33471966/

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