代码之家  ›  专栏  ›  技术社区  ›  Thomas Clayson

按一个键然后按另一个键对数组排序?

  •  0
  • Thomas Clayson  · 技术社区  · 15 年前

    基本上我有一系列字典,每本字典都有 day month year 字段。

    ,然后由 . 好像在整理一个日期。

    这可能吗。这是我目前要按“日期”整体排序的:

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

    有没有办法做到三次分类,然后按年,然后按月(保持年结构),然后按天(保持年和月结构)。

    谢谢

    1 回复  |  直到 15 年前
        1
  •  4
  •   Alex Reynolds    15 年前
    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];