basically I have an array of dictionaries and each dictionary has a day
, month
and year
field.
I want to be able to sort the array by year
, then by month
, then by day
. As if sorting a date.
Is this possible. This is what I have at the moment to sort by "date" as a whole:
NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
[winesOfTheWeek sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
Is there any way to do it three times so it sorts it by year, then by month 开发者_如何学Python(keeping the year structure) and then by day (keeping the year and month structure).
Thanks
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];
精彩评论