how to sort nsmutablearray in ascending order with time comparison
This question already has an answer here:
你可以使用下面的代码升序排列数组:
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: YES];
return [myArray sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]];
请使用以下代码: -
NSMutableArray *listOfTime = [[NSMutableArray alloc] initWithObjects:@"9:30",@"8:30",@"8:45",@"6:45",@"7:30", nil];
NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:nil ascending:YES];
NSArray *sorters = [[NSArray alloc] initWithObjects:sorter, nil];
NSArray *sortedArray = [listOfTime sortedArrayUsingDescriptors:sorters];
NSMutableArray *sortArray = [[NSMutableArray alloc] init];
[sortArray addObjectsFromArray:sortedArray];
NSLog(@"sortArray : %@",sortArray);
链接地址: http://www.djcxy.com/p/70814.html