Created
August 20, 2013 12:30
-
-
Save swizzlr/6280756 to your computer and use it in GitHub Desktop.
A thing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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; | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why does this import Core Graphics? Swizzlr of 5 months ago, you disappoint me.