检查 NSDictionary 中是否存在键
如何检查该密钥是否存在?:
[[dataArray objectAtIndex:indexPathSet.row] valueForKey:@"SetEntries"]
我想知道该密钥是否存在。我怎样才能做到这一点?
非常感谢:)
编辑: dataArray 中有对象。这些对象就是 NSDictionaries。
how can I check if this exists?:
[[dataArray objectAtIndex:indexPathSet.row] valueForKey:@"SetEntries"]
I want to know whether this key exists or not. How can I do that?
Thank you very much :)
EDIT:
dataArray has Objects in it. And these objects are NSDictionaries.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
检查字典是否包含任何值。我更喜欢 [dic allKeys].count > 0 进行检查。
Check dictionary contains any value. I prefer [dic allKeys].count > 0 to check.
使用
(unsigned long)
选项:Use the
(unsigned long)
option:我认为
[dataArray objectAtIndex:indexPathSet.row]
返回NSDictionary
,在这种情况下,您可以简单地检查valueForKey
与nil 的结果。
例如:
I presume that
[dataArray objectAtIndex:indexPathSet.row]
is returning anNSDictionary
, in which case you can simply check the result ofvalueForKey
againstnil.
For example:
所以我知道您已经选择了一个答案,但我发现这作为
NSDictionary
上的一个类别非常有用。此时,您将开始通过所有这些不同的答案来提高效率。嗯... 1 中的 6...So I know you already selected an answer, but I found this to be rather useful as a category on
NSDictionary
. You start getting into efficiency at this point with all these different answers. Meh...6 of 1...检查是否为零:
Check if it's nil:
这也适用于使用以下语法的 Objective-C 文字:
this also works using Objective-C literals using the following syntax:
试试这个:
Try this:
这个功能与此相同,但代码更少:
This one does the same but with less code:
这是正确的答案。
That's the right answer.