Created
August 10, 2018 08:44
-
-
Save Viveron/914bb7e471f98d795470a8950f7ae48b to your computer and use it in GitHub Desktop.
Helpful Obj-C macroses
This file contains 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
#define IS_IPHONE UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone | |
#define IS_IPAD UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad | |
#define SYSTEM_VERSION_COMPARE(v) [[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] | |
#define IS_OS_EQUAL(v) (SYSTEM_VERSION_COMPARE(v) == NSOrderedSame) | |
#define IS_OS_GREATER(v) (SYSTEM_VERSION_COMPARE(v) == NSOrderedDescending) | |
#define IS_OS_GREATER_OR_EQUAL(v) (SYSTEM_VERSION_COMPARE(v) != NSOrderedAscending) | |
#define IS_OS_LESS(v) (SYSTEM_VERSION_COMPARE(v) == NSOrderedAscending) | |
#define IS_OS_LESS_OR_EQUAL(v) (SYSTEM_VERSION_COMPARE(v) != NSOrderedDescending) | |
#ifdef DEBUG | |
#define DebugLog(format, ...) NSLog(format, ##__VA_ARGS__) | |
#define DebugLogIfError(error, reason) if (error) NSLog(@"%@%@\n%@\n%@", (reason ? reason : @""), error, [error userInfo], [error localizedDescription]) | |
#else | |
#define DebugLog(...) | |
#define DebugLogIfError(...) | |
#endif | |
#define safe_block(block, ...) if (block) block(__VA_ARGS__) | |
#define safe_value(value, default) (value ?: default) | |
#define safe_string(value) safe_value(value, @"") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment