Skip to content

Instantly share code, notes, and snippets.

@anddam
Created October 7, 2013 07:45
Show Gist options
  • Save anddam/6863971 to your computer and use it in GitHub Desktop.
Save anddam/6863971 to your computer and use it in GitHub Desktop.
#pragma mark SORTING FUNCTIONS
NSInteger sortData(id num1, id num2, BOOL ascending)
{
float v1 = [[num1 objectAtIndex:0] floatValue];
float v2 = [[num2 objectAtIndex:0] floatValue];
if (v1 < v2)
return (ascending ? NSOrderedAscending : NSOrderedDescending);
else if (v1 > v2)
return (ascending ? NSOrderedDescending : NSOrderedAscending);
else
return NSOrderedSame;
}
NSInteger sortDataAscending (id num1, id num2, void *context) {
return sortData(num1, num2, YES); }
NSInteger sortDataDescending (id num1, id num2, void *context) {
return sortData(num1, num2, NO); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment