Skip to content

Instantly share code, notes, and snippets.

@swizzlr
Created August 20, 2013 12:30
Show Gist options
  • Select an option

  • Save swizzlr/6280756 to your computer and use it in GitHub Desktop.

Select an option

Save swizzlr/6280756 to your computer and use it in GitHub Desktop.
A thing
//Do whatever you want with this except apply a GPL license to it.
//credit to @mattt for the below ifndef
//make sure you only give it things that respond to "Frame" and return a CGRect
@class NSArray;
#ifndef NS_ENUM
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
#endif
NS_ENUM(unsigned int, JLPEulerDimension) {
JLPEulerDimensionX,
JLPEulerDimensionY
};
NSArray *sortViewArrayByDimension(NSArray *viewArray, enum JLPEulerDimension dimension);
#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import "JLPOutletCollectionSort.h"
NSArray *sortViewArrayByDimension(NSArray *viewArray, enum JLPEulerDimension dimension) {
switch (dimension) {
case JLPEulerDimensionX: {
return [viewArray sortedArrayUsingComparator:^NSComparisonResult(id view1, id view2) {
if ([view1 frame].origin.x < [view2 frame].origin.x)
return NSOrderedAscending;
else if ([view1 frame].origin.x > [view2 frame].origin.x)
return NSOrderedDescending;
else
return NSOrderedSame;
}];
}
case JLPEulerDimensionY: {
return [viewArray sortedArrayUsingComparator:^NSComparisonResult(id view1, id view2) {
if ([view1 frame].origin.y < [view2 frame].origin.y)
return NSOrderedAscending;
else if ([view1 frame].origin.y > [view2 frame].origin.y)
return NSOrderedDescending;
else
return NSOrderedSame;
}];
}
default:
return nil;
}
}
@swizzlr
Copy link
Author

swizzlr commented Jan 14, 2014

Why does this import Core Graphics? Swizzlr of 5 months ago, you disappoint me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment