基于包含字典的NSArray创建新数组

时间:2012-10-18 11:56:23

标签: objective-c ios arrays nsarray nsdictionary

我有一系列字典,这些字典来自结果类型为NSDictionary的核心数据提取请求:

request.resultType = NSDictionaryResultType;
request.returnsDistinctResults = YES;
request.propertiesToFetch = @[@"endCalYear",@"endMonth",@"periodLength"];

NSArray的示例结果NSDictionary如下所示:

{
    endCalYear = 2007;
    endMonth = 12;
    periodLength = 12;
},
{
    endCalYear = 2006;
    endMonth = 9;
    periodLength = 3;
},
{
    endCalYear = 2006;
    endMonth = 6;
    periodLength = 3;
},
{
    endCalYear = 2006;
    endMonth = 3;
    periodLength = 3;
}

创建(三个)单独数组的最有效方法是什么? endCalYear = 2006,2007,2008;来自NSArray的 endMonth = 3,9,12和 periodLength = 3,6,12?

谢谢!

1 个答案:

答案 0 :(得分:2)

您可以使用valueForKey

NSArray *endCalYearArray = [resultArray valueForKey:@"endCalYear"];