我有一个字典数组,我想获取包含我正在搜索的键的数组的值。
例如我有这个数组叫做locationArray
:
(
{
id = 1,
info =
{
name = "Person1";
address = "Chicago";
};
};
id = 2,
info =
{
name = "Person2";
address = "Chicago";
};
};
id = 3,
info =
{
name = "Person3";
address = "New York";
};
};
);
我想获得所有在芝加哥有地址的人的数组。结果 ( chicagoArray
) 将是这样的:
(
{
id = 1,
info =
{
name = "Person1";
address = "Chicago";
};
};
id = 2,
info =
{
name = "Person2";
address = "Chicago";
};
};
);
我做了这个循环,但我不知道如何处理我的 resultArray:
for (id result in locationArray)
{
if ([[result valueForKeyPath@"info.address"] isEqualToString:@"Chicago"])
{
// What to do inside the resultArray?
// NSArray *resultArray = [[NSArray alloc] initWithObjects:@""];
}
}
我怎样才能做到这一点?谢谢!