NSArray充满了NSDictionaries。 如何find对象的索引?
我有一个充满了NSDictionaries
的array
。 我想find一个词典的index
,但是我对这个词典的了解只是key @"name".
一个value
@"name".
我该怎么做 ?
查找theValue
中第一个字典的索引,其值为@"name"
为theValue
:
NSUInteger index = [theArray indexOfObjectPassingTest: ^BOOL(NSDictionary *dict, NSUInteger idx, BOOL *stop) { return [[dict objectForKey:@"name"] isEqual:theValue]; } ];
如果找不到匹配的对象, index
将会是NSNotFound
。
NSArray *temp = [allList valueForKey:@"Name"]; NSInteger indexValue = [temp indexOfObject:YourText]; NSString *name = [[allList objectAtIndex:indexValue] valueForKey:@"Name"]