NSD字典计数 [英] NSDictionary Count
本文介绍了NSD字典计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何计算账单"里面有多少个项目?
how can I count how many itens do I have inside of "bills"?
bills = (
{
id = 1;
name = "Cursus Nibh Venenatis";
value = "875.24";
},
{
id = 2;
name = "Elit Fusce";
value = "254.02";
}
);
我是这样数的:
NSUInteger keyCount = [resultsDictionary count];
NSLog(@"%i", keyCount);
谢谢!
推荐答案
一个简单的解决方案是假设 OP 想要计算 bills
,它恰好是一个数组,所以解决方案是>
A naive solution would assume the OP wants to count bills
, which happens to be an array, so the solution would be
NSLog(@"Count: %i", [[resultsDictionary objectForKey: @"bills"] count]);
但是,如果您的字典中包含多个要计算的对象,那么将它们全部列举出来是唯一的方法.
However, if you have a dictionary with more than one object you want to count, then enumerating them all is the only way to go.
这篇关于NSD字典计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文