我有一个 NSMutable 对象数组。这些对象表示足球(足球)比赛,并且有一个名为 title
的 NSString
参数(编辑“Arsenal v Chelsea”)和一个名为 NSDate
的参数实际日期
。
我现在使用以下代码按日期对数组进行排序:
NSMutableArray* a = [self getMatchListFromURL:@"http://www.url.com"];
[a sortUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"ActualDate" ascending:YES]]];
很明显,同一天有多场比赛。我想按字母顺序对同一日期发生的比赛进行排序。有没有简单的方法可以做到这一点?
最佳答案
sortUsingDescriptors
方法将 NSSortDescriptor
数组作为参数。因此,您可以将多个排序描述符传递给方法,如下所示:
NSSortDescriptor *sortAlphabetical = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES];
NSSortDescriptor *sortByDate = [NSSortDescriptor sortDescriptorWithKey:@"ActualDate" ascending:YES];
NSArray *sortDescriptors = @[sortAlphabetical, sortByDate];
//perform sorting
[a sortUsingDescriptors:sortDescriptors];
关于objective-c - 按日期排序 NSMutableArray,然后按字母顺序排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29088252/