一个数组包含NSDate对象,如何使用排序描述符对它们进行排序?我正在尝试下面的代码:
NSSortDescriptor * dateSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"Date" ascending:YES];
NSArray * sortedArray = [allDates addObjectsFromArray:[allDates sortedArrayUsingDescriptors:@[dateSortDescriptor]]];
答案 0 :(得分:2)
NSDate符合compare:
方法,而升序是默认顺序
NSArray *sortedArray = [allDates sortedArrayUsingSelector:@selector(compare:)];
答案 1 :(得分:0)
NSSortDescriptor * dateSortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"timeIntervalSince1970" ascending:YES];
NSArray * sortedArray = [allDates addObjectsFromArray:[allDates sortedArrayUsingDescriptors:@[dateSortDescriptor]]];