2016-01-12/23:15:58
The first method is also the usual method, that is, to set a default value as the maximum value, the loop is larger than the maximum value and assigned to the default maximum value, so that the default maximum value after the completion of the loop is the maximum value of the variable:
floatMaxValue =0; for(intK =0; K < [Valuesarr count]; k++) {Nsarray* Tmparr =[[Valuesarr objectatindex:k] objectforkey:kbaiduvalues]; for(inti =0; i < Tmparr.count; i++) { if([[[Tmparr objectatindex:i] Respondstoselector: @selector (floatvalue)]) {if([[Tmparr objectatindex:i] Floatvalue] >maxValue) {MaxValue=[[Tmparr objectatindex:i] floatvalue]; } } } }
///The second approach is that iOS has already encapsulated a good way for us to use Nsarray's Sortedarrayusingcomparator method:
1Nsarray *values =Array;2Nsarray *arraya = [Values Sortedarrayusingcomparator:^nscomparisonresult (IDObj1,IDobj2) {3 if([Obj1 Floatvalue] >[Obj2 Floatvalue]) {4 returnnsordereddescending;5 }6 if([Obj1 Floatvalue] <[Obj2 Floatvalue]) {7 returnnsorderedascending;8 }9 Ten returnNsorderedsame; One}];<pclass="P1">floatMaxValue = [[Arraya <spanclass="S1">lastobject</span>] <spanclass="S1">floatValue</span>];</p>
The maximum and minimum values for scrambling data in iOS