sortedArrayUsingComparator int
Can't you return the comparison result like this,
listPerc = [listItem sortedArrayUsingComparator: ^(id a, id b) {
int first = [[a objectForKey:@"perc"] intValue];
int second = [[b objectForKey:@"perc"] intValue];
if ( first < second ) {
return (NSComparisonResult)NSOrderedAscending;
} else if ( first > second ) {
return (NSComparisonResult)NSOrderedDescending;
} else {
return (NSComparisonResult)NSOrderedSame;
}
}
A very short way of @(Deepak Danduprolu)'s answer
listPerc = [listItem sortedArrayUsingComparator: ^(id a, id b) {
NSNumber *first = @([[a objectForKey:@"perc"] intValue]);
NSNumber *second = @([[b objectForKey:@"perc"] intValue]);
return [first compare:second];
}