Descending: (from big to small)
-(void) sortarraydatas{ [Array_datas sortusingcomparator:^nscomparisonresult (id _nonnull obj1, id _ Nonnull obj2) { rainfallstations *station_one = obj1; Rainfallstations *station_two = obj2; Double totalrain_one = Station_one.totalrain; Double totalrain_two = Station_two.totalrain; if (totalrain_one>totalrain_two) { return nsorderedascending; } else if (Totalrain_one < totalrain_two) { return nsordereddescending; } else{ return nsorderedsame; } ];}
Ascending: (from small to large)
-(void) sortarraydatas{[Array_datas sortusingcomparator:^nscomparisonresult (ID _nonnull obj1, id _nonnull obj2) {rainfallstations*station_one =obj1; Rainfallstations*station_two =Obj2; DoubleTotalrain_one =Station_one.totalrain; DoubleTotalrain_two =Station_two.totalrain; if(totalrain_one>totalrain_two) { returnnsordereddescending; } Else if(Totalrain_one <totalrain_two) { returnnsorderedascending; }Else{ returnNsorderedsame; } }];}
IOS Array Sorting