I have an array of dates that are adding one by one to the table view , but i want to sort them in ascending order irrespective of the sequence added them,can any one help me
            Asked
            
        
        
            Active
            
        
            Viewed 522 times
        
    4 Answers
0
            
            
        NSArray* sortedDateList = [dateList sortedArrayUsingComparator:^(NSDate* dateOne, NSDate* dateTwo) {
    return [dateOne compare:dateTwo];
}];
 
    
    
        Thomas Zoechling
        
- 34,177
- 3
- 81
- 112
0
            
            
        You can use NSMutableArray's method sortUsingComparator, and write your comparison block using NSDate's compare method.
 
    
    
        Cyrille
        
- 25,014
- 12
- 67
- 90
0
            
            
        If you are using NSDate object this should be easy:
NSDate *date1 = ...;
NSDate *date2 = ...;
NSDate *date3 = ...;
NSArray *dates = [NSArray arrayWithObjects:date1,date2,date3,nil];
NSArray *sortedArray = [dates [anArray sortedArrayUsingSelector:@selector(compare:)];
 
    
    
        Felix Lamouroux
        
- 7,414
- 29
- 46
0
            
            
        NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"beginDate" ascending:TRUE];
[myMutableArray sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];
[sortDescriptor release];
Use this sort descriptor for sorting array of dates
 
    
    
        shivangi
        
- 187
- 2
- 14
