Workaround:
When writing OC, you often use a variety of macro definitions, but there seems to be no such definition of macros in Swift, much more by global constants or global functions to achieve this effect. We just need to create a file (assumed to be macro.swift), to use the definition inside, no need to import the header file or something, It can be used in the global.
Import Uikitimport Foundation/** * Instead of # define in OC, list some common macros*///the physical width of the screenLet Kscreenwidth =Uiscreen.mainscreen (). Bounds.size.width//The physical height of the screenLet Kscreenheight =Uiscreen.mainscreen (). Bounds.size.height/** * Besides some simple attributes are expressed directly with constants, it is more recommended to use global functions to define alternative macros*///judging the system versionFunc Kis_ios7 ()->bool {return(Uidevice.currentdevice (). systemversion asNSString). Doublevalue >=7.0}func Kis_ios8 ()-Bool {return(Uidevice.currentdevice (). systemversion asNSString). Doublevalue >=8.0 }//color settings for RgbaFunc Krgba (R:cgfloat, G:cgfloat, B:cgfloat, A:cgfloat)Uicolor {returnUicolor (red:r/255.0, green:g/255.0, blue:b/255.0, ALPHA:A)}//App Sandbox pathFunc Kapppath ()-string! { returnnshomedirectory ()}//Documents PathFunc Kbundledocumentpath ()-string! { returnNssearchpathfordirectoriesindomains (. Documentdirectory,. Userdomainmask,true). First as!String}//Caches PathFunc Kcachespath ()-string! { returnNssearchpathfordirectoriesindomains (. Cachesdirectory,. Userdomainmask,true). First as!String}
Creation of global variables and functions in Swift-swift