Skip to content

Instantly share code, notes, and snippets.

@acoomans
Last active December 28, 2015 22:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acoomans/7573196 to your computer and use it in GitHub Desktop.
Save acoomans/7573196 to your computer and use it in GitHub Desktop.
Macros for handling iOS API availabilities, disabling deprecation warnings in both clang and deploymate
#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_EQUAL_OR_GREATER_THAN(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_EQUAL_OR_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
// pragmas
#define PRAGMA_AVAILABLE_PUSH \
_Pragma("deploymate push \"ignored-api-availability\"") \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wdeprecated\"")
#define PRAGMA_AVAILABLE_POP \
_Pragma("clang diagnostic pop") \
_Pragma("deploymate pop")
// availability if
#define AVAILABLE_API_IF_EQUAL_TO(v) \
PRAGMA_AVAILABLE_PUSH \
if SYSTEM_VERSION_EQUAL_TO(v) {
#define AVAILABLE_API_IF_GREATER_THAN(v) \
PRAGMA_AVAILABLE_PUSH \
if SYSTEM_VERSION_GREATER_THAN(v) {
#define AVAILABLE_API_IF_EQUAL_OR_GREATER_THAN(v) \
PRAGMA_AVAILABLE_PUSH \
if SYSTEM_VERSION_EQUAL_OR_GREATER_THAN(v) {
#define AVAILABLE_API_IF_LESS_THAN(v) \
PRAGMA_AVAILABLE_PUSH \
if SYSTEM_VERSION_LESS_THAN(v) {
#define AVAILABLE_API_IF_EQUAL_OR_LESS_THAN(v) \
PRAGMA_AVAILABLE_PUSH \
if SYSTEM_VERSION_EQUAL_OR_LESS_THAN(v) {
// availability else/end
#define AVAILABLE_API_ELSE } else {
#define AVAILABLE_API_END \
} \
PRAGMA_AVAILABLE_POP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment