- (NSArray *)sortedDateArrayWithExistedArray:(NSMutableArray *) setExistedArray acending:(BOOL)ascendingBoolvalue { NSArray *sortedArray = [setExistedArray sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"dd MMM, yyyy"]; NSDate *d1 = [formatter dateFromString:obj1[@"displayDate"]]; NSDate *d2 = [formatter dateFromString:obj2[@"displayDate"]];
set setExistedArray == yourArray
set the ascending parameter as yes or no based on your requirement yes for the ascending order no to decreasing.
how to access this function
self.sortedArray = [[self sortedDateArrayWithExistedArray: self.yourArray Acquisition: NO] mutableCopy];
if yourArray is a mutable call forwarding method, otherwise there is no need
source share