IOS development common macro, continuous updates

Everyone knows that using macros is not only convenient, but also improves development efficiency. The following summarizes some common macros in the iOS development process that will continue to be added to it.

Whether a string is empty #define / kStringIsEmpty (STR) ([str isKindOfClass:[NSNull class]] STR nil [str length] || || = < 1? YES: / / NO) array is empty #define kArrayIsEmpty (array) (array = nil [array isKindOfClass:[NSNull class]] || || array.count = = 0) / / dictionary is empty (DIC (DIC) #define kDictIsEmpty nil [dic isKindOfClass:[NSNull class]] || || = = dic.allKeys = = 0) / / if it is empty object #define (_object) kObjectIsEmpty (_object = nil / [_object isKindOfClass:[NSNull / class]] || || ([_object respondsToSelector:@selector (length)] & & [(NSData *) _object length] = = 0) / || ([_object respondsToSelector:@selector (count)] & & [(NSArray *) _object count] = = 0)) / / get the screen width and height ([[UISc / #define kScreenWidth Reen mainScreen] respondsToSelector:@selector (nativeBounds)] [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale?: [UIScreen mainScreen].bounds.size.width #define kScreenHeight ([[UIScreen) / mainScreen] respondsToSelector:@selector (nativeBounds)] [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale?: [UIScreen mainScreen].bounds.size.height kScreenSize ([[UIScreen) #define / mainScreen] respondsToSelector:@ selector (nativeBounds)] CGSizeMake ([UIScreen? MainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale, [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale): [UIScreen / / mainScreen].bounds.size) some abbreviations #define kApplication [UIApplication sharedApplication] #define kKeyWindow [UIApplication sharedApplication].keyWindow #define kAppDelegate [UIApplication sharedApplication].delegate #define kUserDefaults [NSUserDefaults standardUserDefaults] #define kNotificationCenter [NSNotificationCenter defaultCenter] //APP #define kAppVersion [[[NSBundle mainBundle] infoDictionary] version of objectForKey:@ "CFBundleShortVersionString"] / / #define kSystemVersion [[UIDevice currentDevice] system version number systemVersion] / / #define kCurrentLanguage to obtain the current language ([[NSLocale preferredLanguages] objectAtIndex:0]) to determine whether iPhone #define kISiPhone / UI_USER_INTERFACE_IDIOM ((= =) UIUserInterfaceIdiomPhone / /) to determine whether iPad #define kISiPad (UI_ (USER_INTERFACE_IDIOM) = = UIUserInterfaceIdiomPad) / / get Document kDocumentPath [NSSearchPathForDirectoriesInDomains sandbox path #define (NSDocumentDirectory, NSUserDomainMask, YES) firstObject] / temp #define kTempPath NSTemporaryDirectory sandbox access path (Cache) / / get the path #define kCachePath [NSSearchPathForDirectoriesInDomains sandbox (NSCachesDirectory, NSUserDomainMask, YES) firstObject] / / judgment is a real machine or simulator #if TARGET_OS_IPHONE / / TARGET_IPHONE_SIMULATOR / / #if #endif real machine simulator #endif / / time to the development of printing, but not print when released NSLog #ifdef DEBUG #define NSLog (...) NSLog (@%s line%d /n%@/n/n __func__, __LINE__, [NSString, stringWithFormat:__VA_ARGS__]) #else # define NSLog (...) #endif / / color #define kRGBColor (R, G, b) [UIColor colorWithRed: (R) /255.0 green: (g) /255.0 blue: (b) /255.0 alpha:1.0] #define kRGBAColor (R, G, B, a) [UIColor colorWithRed: (R) /255.0 green: (R) /255.0 blue: (R) /255.0 alpha:a] #define kRandomColor kRGBColor (arc4random_uniform (256), arc4random_uniform (256), arc4random_uniform (256)) #define kColorWithHex (rgbValue) / [UIColor (colorWithRed: (float) ((rgbValue & > > 0xFF0000) 16 / green: (255)) / ((float) (rgbValue & > > 0xFF00) 8)) ((float / 255 / blue: (rgbValue) & 0xFF)) / 255 / / alpha:1.0] / #define kWeakSelf strong weak reference reference (type) __weak typeof (type) weak##type = type; # define kStrongSelf (type) __strong typeof (type) type = weak##type; / / #define kDegre by angle radians EsToRadian (x) (M_PI * (x) / 180) / / #define kRadianToDegrees by arc angle conversion (radian) (radian * 180) / (M_PI) / / get a time interval of #define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent (#define); kEndTime NSLog (@ Time:) -%f, CFAbsoluteTimeGetCurrent (start)

Continuous update…….

Welcome to pay attention to me and my topic: iOS technical exchange, check out more good articles.