NSArray充满了NSDictionaries。如何找到对象的索引? [英] NSArray full of NSDictionaries. How to find index of object?

查看:178
本文介绍了NSArray充满了NSDictionaries。如何找到对象的索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组,里面装满了 NSDictionaries 。我想找到一个字典的索引,但我对这个字典的了解只是 @name。
我该怎么办?

I have an array which is filled with NSDictionaries. I want to find the index of one of the dictionary, but what I know about this dictionary is only a value for key @"name". How do I do it ?

推荐答案

theArray 中查找第一个字典的索引,其值为 @name theValue

Find index of first dictionary in theArray whose value for @"name" is theValue:

NSUInteger index = [theArray indexOfObjectPassingTest:
        ^BOOL(NSDictionary *dict, NSUInteger idx, BOOL *stop)
        {
            return [[dict objectForKey:@"name"] isEqual:theValue];
        }
];

index NSNotFound 如果找不到匹配的对象。

index will be NSNotFound if no matching object is found.

这篇关于NSArray充满了NSDictionaries。如何找到对象的索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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