Skip to content

Instantly share code, notes, and snippets.

@aschuch
Created August 18, 2013 16:13
Show Gist options
  • Save aschuch/6262443 to your computer and use it in GitHub Desktop.
Save aschuch/6262443 to your computer and use it in GitHub Desktop.
Collection of helpful Objective-C macros.
/**
Determine System Version
Usage: if (SYSTEM_VERSION_LESS_THAN(@"4.0")) { ... }
*/
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
/**
Hex color to UIColor conversion
Usage: UIColorFromRGB(0xFF0033)
*/
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment