Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Sort UIColors in a human way (snippet from
NSArray *sorted = [[dict allValues] sortedArrayUsingComparator:^NSComparisonResult(UIColor* obj1, UIColor* obj2) {
float hue, saturation, brightness, alpha;
[obj1 getHue:&hue saturation:&saturation brightness:&brightness alpha:&alpha];
float hue2, saturation2, brightness2, alpha2;
[obj2 getHue:&hue2 saturation:&saturation2 brightness:&brightness2 alpha:&alpha2];
if (hue < hue2)
return NSOrderedAscending;
else if (hue > hue2)
return NSOrderedDescending;
if (saturation < saturation2)
return NSOrderedAscending;
else if (saturation > saturation2)
return NSOrderedDescending;
if (brightness < brightness2)
return NSOrderedAscending;
else if (brightness > brightness2)
return NSOrderedDescending;
return NSOrderedSame;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.