NSDictionary中存在检查键 [英] Check key exists in NSDictionary

查看:130
本文介绍了NSDictionary中存在检查键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查是否存在?:

[[dataArray objectAtIndex:indexPathSet.row] valueForKey:@"SetEntries"]

我想知道这个密钥是否存在。我怎么能这样做?

I want to know whether this key exists or not. How can I do that?

非常感谢:)

编辑:
dataArray中有对象。这些对象是NSDictionaries。

推荐答案

我认为 [dataArray objectAtIndex:indexPathSet。 row] 返回 NSDictionary ,在这种情况下,你可以简单地检查valueForKey的结果与nil。

I presume that [dataArray objectAtIndex:indexPathSet.row] is returning an NSDictionary, in which case you can simply check the result of valueForKey against nil.

例如:

if([[dataArray objectAtIndex:indexPathSet.row] valueForKey:@"SetEntries"] != nil) {
    // The key existed...

}
else {
    // No joy...

}

这篇关于NSDictionary中存在检查键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆