2010-11-12 75 views
0

基本上我有一个字典阵列,每个字典有一个day,monthyear字段。按一个键然后另一个键排序数组?

我希望能够按year排序数组,然后按month,然后按day排序。就像排序日期一样。

这是可能的。这是我目前所面对的“日期”作为一个整体来进行排序:

NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO]; 
[winesOfTheWeek sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]]; 

有没有办法做到这一点三倍,因此在今年进行排序,然后按月份(保持年结构)然后按天(保持年和月结构)。

谢谢

回答

4
NSSortDescriptor *yearSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"year" ascending:NO]; 
NSSortDescriptor *monthSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"month" ascending:NO]; 
NSSortDescriptor *daySortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"day" ascending:NO]; 
[winesOfTheWeek sortUsingDescriptors:[NSArray arrayWithObjects:yearSortDescriptor, monthSortDescriptor, daySortDescriptor, nil]]; 
[daySortDescriptor release]; 
[monthSortDescriptor release]; 
[yearSortDescriptor release]; 
相关问题