配列内の各オブジェクトに対してvalueForKey:を実行して、その結果を配列として返すものである。
NSDictionary *dict1 = [NSDictionary dictionaryWithObjectsAndKeys:@"ABC", @"theKey", nil];
NSDictionary *dict2 = [NSDictionary dictionaryWithObjectsAndKeys:@"DEF", @"theKey", nil];
NSArray *anArray = [NSArray arrayWithObjects:dict1, dict2, nil];
NSLog(@"%@", [anArray valueForKey:@"theKey"]);
応用例
特定のキーの値を持つオブジェクトを配列の中から探す。 [[anArray valueForKey:@"theKey"] indexOfObject:@"theValue"];
この例では、キー"theKey"の値がtheValueである辞書が配列内で最初に現れる位置を返す。