Ios NSN字典的排序数组,其中包含字典数组

Ios NSN字典的排序数组,其中包含字典数组,ios,nspredicate,Ios,Nspredicate,我需要使用items dictionary的“Date”键对数组进行排序。最后,我需要具有某种结构的数组作为我的mData数组,但要使用排序日期 mData------>( { 项目=( { 精度=5; 地址=“澳大利亚,悉尼CBD,布里奇街”; 课程=“0.00”; 日期=“2013-08-2006:50:28+0000”; 速度=3; alt=0; lat=“-33.8634”; lon=“151.211”; }, { 准确度=65; 地址=“埃里温亚美尼亚,\U053f\U0561\U05

我需要使用items dictionary的“Date”键对数组进行排序。最后,我需要具有某种结构的数组作为我的mData数组,但要使用排序日期

mData------>(
{
项目=(
{
精度=5;
地址=“澳大利亚,悉尼CBD,布里奇街”;
课程=“0.00”;
日期=“2013-08-2006:50:28+0000”;
速度=3;
alt=0;
lat=“-33.8634”;
lon=“151.211”;
},
{
准确度=65;
地址=“埃里温亚美尼亚,\U053f\U0561\U056c\U0565\U0576\U0581\U056b\U0583\U0578\U0572\U0578\U0581”;
课程=“0.00”;
日期=“2013-08-2006:41:02+0000”;
速度=3;
alt=1116;
lat=“40.20016076”;
lon=“44.49
在此处输入代码
130268”;
}
);
名称=名称;
startTime=“10:40”;
}
)
我的阵列看起来像 2.
NSDictionary*mFirst=[NSDictionary Dictionary WithObjectsAndKeys:[NSDate distantFuture],@“Date”,nil];
NSDictionary*mSecond=[NSDictionary Dictionary WithObjectsSandKeys:[NSDate distantPast],@“Date”,nil];
NSArray*mArr=[[NSArray alloc]initWithObjects:mFirst,mSecond,nil];
NSDictionary*myDict=[NSDictionary Dictionary WithObject:mArr forKey:@“items]”;
NSArray*mSortedArray=[[NSArray alloc]initWithObjects:myDict,nil];
NSLog(@“%@”,mSortedArray)

使用以下命令:

    NSSortDescriptor *dateDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"Date" ascending:YES] autorelease];
    NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
    NSArray *sortedArray = [myArray sortedArrayUsingDescriptors:sortDescriptors];
更新: 我用过这个:

NSArray *myArray = [[NSArray alloc] initWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:[NSDate distantFuture], @"Date", nil],
        [NSDictionary dictionaryWithObjectsAndKeys:[NSDate distantPast], @"Date", nil], nil];
    NSLog(@"%@", myArray);
    NSSortDescriptor *dateDescriptor = [[NSSortDescriptor alloc] initWithKey:@"Date" ascending:YES];
    NSArray *sortDescriptors = [NSArray arrayWithObject:dateDescriptor];
    NSArray *sortedArray = [myArray sortedArrayUsingDescriptors:sortDescriptors];
    NSLog(@"%@", sortedArray);
并得到日志:

排序前: ( { 日期=“4001-01-01 00:00:00+0000”; }, { 日期=“0001-12-30 00:00:00+0000”; } ) 排序后: ( { 日期=“0001-12-30 00:00:00+0000”; }, { 日期=“4001-01-01 00:00:00+0000”; } )


使用上述代码时请检查。

您是否记录了SorterDarray?是的,但我不能在这里发布它--按951个字符太长您有字典数组,并且您希望根据字典中的日期键对数组进行排序?字典将显示它,但您将根据日期键对数组进行排序。您到底想要什么?