我有一个array
,里面充满了NSDictionaries
。我想找到其中一本字典的index
,但是我对这本字典的了解只是关键value
的@"name".
我该怎么做 ?
最佳答案
在theArray
中查找其@"name"
的值为theValue
的第一本词典的索引:
NSUInteger index = [theArray indexOfObjectPassingTest:
^BOOL(NSDictionary *dict, NSUInteger idx, BOOL *stop)
{
return [[dict objectForKey:@"name"] isEqual:theValue];
}
];
如果找不到匹配的对象,则
index
将为NSNotFound
。