Skip to content

Instantly share code, notes, and snippets.

@mwaterfall
Created May 3, 2011 16:24
Show Gist options
  • Save mwaterfall/953657 to your computer and use it in GitHub Desktop.
Save mwaterfall/953657 to your computer and use it in GitHub Desktop.
Runtime iOS Version Checking
/*
* System Versioning Preprocessor Macros
*/
#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)
/*
* Usage
*/
if (SYSTEM_VERSION_LESS_THAN(@"4.0")) {
...
}
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"3.1.1")) {
...
}
@mwaterfall
Copy link
Author

Simple preprocessor macros to detect the current iOS version at runtime.

The NSNumericSearch compare option is very clever and can evaluate various types of numeric strings, including period separated integer strings!

@trailblazr
Copy link

thx. this is helpful and will extend my UIDevice category.

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