We all know that using macros is not only convenient, but also can improve development efficiency. Here's a summary of some of the common macros in the iOS development process that will continue to be added.
Objective-c
Whether the string is empty #define KSTRINGISEMPTY (str) ([str iskindofclass:[nsnull class]] | | |-str = NIL | | [STR length] < 1? Yes:no)//array is empty #define KARRAYISEMPTY (array = = Nil | | [Array Iskindofclass:[nsnull class]] | | Array.count = = 0)//dictionary is empty #define KDICTISEMPTY (DIC) (dic = = Nil | | [DIC Iskindofclass:[nsnull class]] | | Dic.allkeys = = 0)/is 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 current language #define KCURRENTLANGUAGE ([[[Nslocale Preferredlanguages] objectatindex:0])//Determine if iphone # Define Kisiphone (Ui_user_interface_idiom () = Uiuserinterfaceidiomphone)//judge whether the ipad #define KISIPAD (Ui_user_interface_ IDIOM () = = Uiuserinterfaceidiompad)//Get sandbox document path #define KDOCUMENTPATH [Nssearchpathfordirectoriesindomains ( NSDocumentDirectory, Nsuserdomainmask, YES) Firstobject]//Get Sandbox temp path #define KTEMPPATH nstemporarydirectory ()// Get the Sandbox cache path #define Kcachepath [Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) Firstobject]//judge whether the real machine or the simulator #if target_os_iphone//Real machine #endif #if target_iphone_simulator//Simulator #endif//development time print, but not when released Printed 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 Krgbacol or (R, G, B, a) [Uicolor colorwithred: (r)/255.0 Green: (r)/255.0 Blue: (R)/255.0 alpha:a] #define Krandomcolor krgbcolor (arc 4random_uniform (256)/255.0,arc4random_uniform (256)/255.0,arc4random_uniform (256)/255.0) #define KCOLORWITHHEX (rgbvalue) \ [UIColor Colorwithred: ((Rgbvalue & 0xff0000) >>)/255.0/green: ((float) ((Rgbvalue & 0xff00) >> 8) /255.0 \ Blue: ((float) (Rgbvalue & 0xFF)/255.0 alpha:1.0]//Weak reference/strong reference #define KWEAKSELF (type) __weak typeof (Type)
weak# #type = type;
#define KSTRONGSELF (Type) __strong typeof (type) type = weak# #type; Convert from angle to radians #define Kdegreestoradian (x) (M_PI * (x)/180.0)//from radians conversion angle #define KRADIANTODEGREES (radian) (Radian * 180.0)/
(M_PI)//Get a period of time interval #define Kstarttime cfabsolutetime start = Cfabsolutetimegetcurrent ();
#define Kendtime NSLog (@ "Time:%f", Cfabsolutetimegetcurrent ()-start)
1. Define macro for Dimension class
DimensMacros.h
//status bar height
#define Status_bar_height
//navbar height
#define Navigation_bar_height 44
//status bar + navigation bar height
#define Status_and_navigation_height ((status_bar_height) + (navigation_bar_height))
//Screen Rect
#define SCREEN_RECT ([UIScreen mainscreen].bounds)
#define SCREEN_WIDTH ([UIScreen mainscreen]. Bounds.size.width)
#define Screen_height ([UIScreen mainscreen].bounds.size.height)
#define Content_ HEIGHT (screen_height-navigation_bar_height-status_bar_height)
//Screen Resolution
#define SCREEN_RESOLUTION ( Screen_width * screen_height * ([UIScreen mainscreen].scale))
//advertisement height
#define Banner_height 215
# Define Stylepage_height
#define Smalltv_height
#define SMALLTV_WIDTH
#define Follow_height
#define Subchannel_height 62
2. Macros that define sandbox directory files
PathMacros.h
//file directory
#define KPATHTEMP nstemporarydirectory ()
#define Kpathdocument [ Nssearchpathfordirectoriesindomains (NSDocumentDirectory, Nsuserdomainmask, YES) objectatindex:0]
#define Kpathcache [Nssearchpathfordirectoriesindomains (Nscachesdirectory, Nsuserdomainmask, YES) objectAtIndex:0]
#define Kpathsearch [Kpathdocument stringbyappendingpathcomponent:@ "Search.plist"]
#define Kpathmagazine [kpathdocument stringbyappendingpathcomponent:@ "Magazine"]
#define Kpathdownloadedmgzs [kpathmagazine stringbyappendingpathcomponent:@ "downloadedmgz.plist"]
#define Kpathdownloadurls [kpathmagazine stringbyappendingpathcomponent:@ "downloadurls.plist"]
#define Kpathoperation [kpathmagazine stringbyappendingpathcomponent:@ "operation.plist"]
#define Kpathsplashscreen [Kpathcache stringbyappendingpathcomponent:@ "SplashScreen"]
#endif
3. Macro for Tool class
UtilsMacros.h//log utils Marco #define Alog (FMT, ...)
NSLog ((@ "%s [line%d]" FMT), __pretty_function__, __line__, # #__VA_ARGS__); #ifdef DEBUG #define Dlog (FMT, ...)
NSLog ((@ "%s [line%d]" FMT), __pretty_function__, __line__, # #__VA_ARGS__); #else #define Dlog (...) #endif #ifdef DEBUG #define ULOG (...)//#define ULOG (FMT, ...) {Uialertview *alert = [[Uialertview alloc] initwithtitle:[nsstring stringwithformat:@ "%s\n [line%d]", __pretty_functio n__, __line__] message:[nsstring stringwithformat:fmt, # #__VA_ARGS__] delegate:nil cancelbuttontitle:@ "OK" Otherbuttontitles:nil]; [Alert show]; #else #define Ulog (...) #endif//system version utils #define SYSTEM_VERSION_EQUAL_TO (v) ([[Uidevice Current Device] systemversion] compare:v options:nsnumericsearch] = = nsorderedsame) #define System_version_greater_than (v) ( [[[Uidevice Currentdevice] systemversion] compare:v options:nsnumericsearch] = = nsordereddescending) #define SYSTEM_ Version_greater_than_or_equal_to (v) ([[[Uidevice Currentdevice] systemversion] compare:v Options:nsnumericsearch]!= nsorderedascending) #define SYSTEM_ Version_less_than (v) ([[[[Uidevice Currentdevice] systemversion] compare:v options:nsnumericsearch] = = NSORDEREDASC Ending) #define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO (v) ([[[Uidevice Currentdevice] systemversion] compare:v options: Nsnumericsearch]!= nsordereddescending)//Get RGB color #define RGBA (r,g,b,a) [Uicolor colorwithred:r/255.0f green:g/255.0f blue:b/255.0f Alpha:a] #define RGB (r,g,b) RGBA (r,g,b,1.0f) #define ISPORTRAIT ([UIApplication Sharedapplication].statu Sbarorientation = = Uiinterfaceorientationportrait | | [UIApplication sharedapplication].statusbarorientation = = uiinterfaceorientationportraitupsidedown) #define Isnilornull (_ref) ((_ref) = = Nil) | |
([(_REF) isequal:[nsnull NULL]]) Angular arc #define Degrees_to_radians (d) (d * m_pi/180)//iOS version greater than or equal to 7.0 #define Ios7_or_later System_version_greater_than_ Or_equal_to (@ "7.0")//iOS version greater than or equal to 8.0 #definE ios8_or_later system_version_greater_than_or_equal_to (@ "8.0")//IOS6, navigation VC view in the starting Height #define Yh_height (ios7_or_ Later?
64:0//Get system timestamp #define GETCURENTTIME [nsstring stringwithformat:@ '%ld ', (long) [[NSDate Date] timeIntervalSince1970]]
4. Notify notification related macros
NOTIFICATIONMACROS.H//System Notification definition #define TNCANCELFAVORITEPRODUCTNOTIFICATION @ " Tncancelfavoriteproductnotification "//Cancel Collection #define Tnmarkfavoriteproductnotification @" Tnmarkfavoriteproductnotification "//Mark Collection #define Knotficationdownloadprogresschanged @" knotficationdownloadprogresschanged "//Download Progress change #define KNOTIFICATIONPAUSEDOWNLOAD @" Knotificationpausedownload " Pause download #define Knotificationstartdownload @ "Knotificationstartdownload"//Start download #define Knotificationdown loadsuccess @ "knotificationdownloadsuccess"//Download Success #define KNOTIFICATIONDOWNLOADFAILED @ "Knotificationdow Nloadfailed "///Download failure #define Knotificationdownloadnewmagazine @" Knotificationdownloadnewmagazine "server-side API Interface Macro APIs
TringMacros.h//////////////////////////////////////////////////////////////////////////////////////////////////
Interface name-related #ifdef DEBUG//debug State test API #define Api_base_url_string @ "http://boys.test.companydomain.com/api/" #elseThe online API in release State #define Api_base_url_string @ "http://www.companydomain.com/api/" #endif//interface #define Get_content_d Etail @ "Channel/getcontentdetail"//Get content details (including previous and next) #define Get_comment_list @ "comment/getcommentlist"//Get Comment List # Define Comment_login @ "Comment/login"//Get Comments List #define Comment_publish @ "Comment/publish"//post comments #defi NE comment_delete @ "comment/delcomment"//Delete comment #define Loginout @ "Common/logout"//Logout There are many other types of macros, not one here Enumerates the files associated with creating an import all macros Macros.h Macros.h #import "UtilsMacros.h" #import "APIStringMacros.h" #import "DimensMacros.h" #im Port "NotificationMacros.h" #import "SharePlatformMacros.h" #import "StringMacros.h" #import "UserBehaviorMacros.h" Import "PathMacros.h" in the PCH file for the Xcode project, importing the Macros.h file xcodeprojectname-prefix.pch #ifdef __objc__ #import <uikit/
uikit.h> #import <Foundation/Foundation.h> #import "Macros.h" #endif
Above is the iOS commonly used macro data collation, follow-up continue to supplement the relevant information, thank you for the support of this site!