how to sort nsmutablearray in ascending order with time comparison

This question already has an answer here:

  • How do I sort an NSMutableArray with custom objects in it? 25 answers

  • 你可以使用下面的代码升序排列数组:

    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

    上一篇: 用另一个NSMutableArray将自定义对象排序为NSMutableArray

    下一篇: 如何以时间比较的升序对nsmutablearray进行排序