我有以下数组:
myArrey = (
object1:{key1:valueA, key2:valueB},
object2:{key1:valueC, key2:valueD}
)
我需要做些什么才能找到一个对象,即key1的值是keyC?
MyObject obj = [myArrey abrakadabra with: key1 and:valueC];
NSLog(@"obj - %@",obj);
obj = object2
答案 0 :(得分:1)
使用indexOfObjectPassingTest:
NSInteger indexOfMatchingDictionary = [myArray indexOfObjectPassingTest:^BOOL(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
return [[obj valueForKey:@"key1"] isEqual:@"valueC"];
}
NSDictionary *matchingDictionary = [myArray objectAtIndex:indexOfMatchingDictionary];