//whether the string is empty#defineKstringisempty (str) ([str iskindofclass:[nsnull class]] | | str = = NIL | | [STR length] < 1? Yes:no)//whether the array is empty#defineKarrayisempty (array) (array = = Nil | | [Array Iskindofclass:[nsnull class] | | Array.count = = 0)//whether the dictionary is empty#defineKdictisempty (DIC) (dic = = Nil | | [dic Iskindofclass:[nsnull class] | | Dic.allkeys = = 0)//whether it is an empty object#defineKobjectisempty (_object) (_object = = Nil | | [_object Iskindofclass:[nsnullclass]] || ([_object respondstoselector: @selector (length)] && [(NSData *) _object length] = =0) || ([_object respondstoselector: @selector (count)] && [(Nsarray *) _object count] = =0)) //Get screen width and height#defineKscreenwidth \([[UIScreen mainscreen] Respondstoselector: @selector (nativebounds)]? [UIScreen mainscreen].nativebounds.size.width/[UIScreen mainscreen].nativescale: [UIScreen mainscreen].bounds.size.width]#defineKscreenheight \([[UIScreen mainscreen] Respondstoselector: @selector (nativebounds)]? [UIScreen mainscreen].nativebounds.size.height/[UIScreen mainscreen].nativescale: [UIScreen mainscreen].bounds.size.height]#defineKscreensize \([[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#definekapplication [UIApplication Sharedapplication]#defineKkeywindow [UIApplication Sharedapplication].keywindow#definekappdelegate [UIApplication sharedapplication].delegate#defineKuserdefaults [Nsuserdefaults Standarduserdefaults]#defineKnotificationcenter [Nsnotificationcenter Defaultcenter]//App version number#definekappversion [[[NSBundle Mainbundle] infodictionary] objectforkey:@ "cfbundleshortversionstring"]//System version Number#defineksystemversion [[Uidevice Currentdevice] systemversion]//get the current language#defineKcurrentlanguage ([[Nslocale preferredlanguages] objectatindex:0])//determine if the iphone#defineKisiphone (ui_user_interface_idiom () = = Uiuserinterfaceidiomphone)//determine if the ipad#defineKisipad (ui_user_interface_idiom () = = Uiuserinterfaceidiompad)//get the Sandbox document path#defineKdocumentpath [Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) FirstObject]//Get Sandbox temp path#defineKtemppath Nstemporarydirectory ()//get sandbox cache path#defineKcachepath [Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) FirstObject]//Judging whether it's a real machine or a simulator#ifTarget_os_iphone//Real Machine#endif #ifTarget_iphone_simulator//Analog Device#endif //Print when developing, but not print when publishing NSLog#ifdefDEBUG#defineNSLog (...) NSLog (@ "%s line%d \%@\n\n", __func__,__line__,[nsstring stringwithformat:__va_args__])#else#defineNSLog (...)#endif //Color#defineKrgbcolor (R, G, b) [Uicolor colorwithred: (r)/255.0 Green: (g)/255.0 Blue: (b)/255.0 alpha:1.0]#defineKrgbacolor (R, G, B, a) [Uicolor colorwithred: (r)/255.0 Green: (r)/255.0 Blue: (R)/255.0 Alpha:a]#defineKrandomcolor Krgbcolor (Arc4random_uniform (/255.0,arc4random_uniform)/255.0,arc4random_uniform (256)/ 255.0)#defineKcolorwithhex (Rgbvalue) \[Uicolor colorwithred: ((float) ((Rgbvalue &0xFF0000) >> -)) /255.0Green: ((float) ((Rgbvalue &0xff00) >>8)) /255.0Blue: ((float) (Rgbvalue &0xFF)) /255.0Alpha1.0] //Weak references/strong references#defineKweakself (Type) __weak typeof (Type) weak# #type = type;#defineKstrongself (Type) __strong typeof (type) type = weak# #type;//convert radians from angle#defineKdegreestoradian (x) (M_PI * (x)/180.0)//convert angle from radians#defineKradiantodegrees (Radian) (Radian * 180.0)/(M_PI)//get a time interval#defineKstarttime cfabsolutetime start = Cfabsolutetimegetcurrent ();#defineKendtime NSLog (@ "Time:%f", Cfabsolutetimegetcurrent ()-start)
30th, common macros in IOS development