We all know that using macros is not only convenient, but also can improve development efficiency. The following summarizes some of the commonly used macros in the iOS development process, which will continue to be added.
Whether the string is empty
#define KSTRINGISEMPTY (str) ([str iskindofclass:[nsnull class]] | | str = = NIL | | [STR length] < 1? Yes:no)
Whether the array is empty
#define KARRAYISEMPTY (array) (array = = Nil | | [Array Iskindofclass:[nsnull class] | | Array.count = = 0)
Whether the dictionary is empty
#define KDICTISEMPTY (DIC) (dic = = Nil | | [dic Iskindofclass:[nsnull class] | | Dic.allkeys = = 0)
Whether it is an empty object
#define KOBJECTISEMPTY (_object) (_object = = nil \
|| [_object iskindofclass:[NSNull class]] \
|| ([_object respondstoselector:@selector(length)] && [( nsdata *)_object length] = = 0) \
|| ([_object respondstoselector:@selector(Count)] && [(Nsarray *)_object count] = = 0))
Get screen width and height
#define KSCREENWIDTH \
([[uiscreen 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)
#define KSCREENSIZE \
([[UIScreen 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 version number
#define Kappversion [[[NSBundle Mainbundle] infodictionary] objectforkey:@ "cfbundleshortversionstring"]
System version number
#define Ksystemversion [[Uidevice Currentdevice] systemversion]
Get the current language
#define KCURRENTLANGUAGE ([[Nslocale preferredlanguages] objectatindex:0])
Determine if the iphone
#define Kisiphone (ui_user_interface_idiom () = = Uiuserinterfaceidiomphone)
Determine if the ipad
#define KISIPAD (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)
Get the Sandbox document path
#define Kdocumentpath [Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) FirstObject]
Get Sandbox temp Path
#define Ktemppath nstemporarydirectory ()
Get Sandbox cache Path
#define Kcachepath [Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) FirstObject]
Judging whether it's a real machine or a simulator
#if Target_os_iphone
Real Machine
#endif
#if Target_iphone_simulator
Analog device
#endif
Print when developing, but not print when publishing NSLog
#ifdef DEBUG
#define NSLOG (...) NSLog (@ "%s line%d \%@\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 (/255.0,arc4random_uniform)/255.0,arc4random_uniform ( 256)/255.0)
#define KCOLORWITHHEX (Rgbvalue) \
[uicolor colorwithred:((float) ((rgbvalue & 0xFF0000) >> )) / 255.0 \
Green:((float) ((rgbvalue & 0xff00) >> 8)) / 255.0 \
Blue:((float) (rgbvalue & 0xFF)) / 255.0 Alpha: 1.0]
Weak references/strong references
#define KWEAKSELF (Type) __weak typeof (Type) weak# #type = type;
#define KSTRONGSELF (Type) __strong typeof (type) type = weak# #type;
Convert radians from angle
#define Kdegreestoradian (x) (M_PI * (x)/180.0)
Convert angle from radians
#define Kradiantodegrees (Radian) (Radian * 180.0)/(M_PI)
Get a time interval
#define Kstarttime Cfabsolutetime start = Cfabsolutetimegetcurrent ();
#define Kendtime NSLog (@ "Time:%f", Cfabsolutetimegetcurrent ()-start)
Keep updating ....