如何在 iPhone 中获取 NSMutableDictionary 计数?
我想获取 iphone 中的 NSMutableDictionary 计数。我想知道 NSMutableDictionry 中有多少项。我尝试了这些代码来找出解决方案,但是对我没有多大帮助。
NSLog(@"Count : %d", [mutableDictionary count]);
它总是返回“0”。如何获取 iPhone 中 NSMutableDictionary 的数量?提前致谢。
I want to get NSMutableDictionary count in iphone. I want to know how many items are in NSMutableDictionry. I tried these code to find out the solution but, not helped me lot.
NSLog(@"Count : %d", [mutableDictionary count]);
It is always returns '0'. How to get the count of NSMutableDictionary in iPhone? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以找出有多少个键-对象(键-值)对,如下所示:
编辑
在查看字典文档后,
NSDictionary
的count
方法(或属性)应该也能工作。我认为您可能收到 0 计数,因为字典为空或为零。我提供了我的解决方案,因为我倾向于更关心枚举键而不是直接计算条目。请考虑您已在其他地方解决了该问题这一事实。
• 通过实际填充字典
或
• 通过修复 mutableDictionary 不知何故为 nil 的错误,
我运行此测试代码并获得注释输出
You can find out how many key-object (key-value) pairs there are like so:
EDIT
Upon looking through the dictionary documentation,
NSDictionary
'scount
method (or property) should work as well. I think you may have been receiving 0 count because the dictionary was empty or nil. I offered my solution because I tend to care more about enumerating the keys than counting the entries directly.Please consider the fact that you fixed the issue somewhere else.
• By actually populating the dictionary
or
• By fixing a bug where mutableDictionary was somehow nil
I run this test code and get the commented output
[[dictionary allKeys] count];
就可以了。[[dictionary allKeys] count];
will do the trick.试试这个
Try this
如果您希望计算可以使用的任何数组项的 NSMutableDictionary 值。
if you looking to count NSMutableDictionary values for any Array item you can use.