Using some commonly used macros during iOS development can improve development efficiency and code reusability; placing these macros in a header file and then putting them in the project-Prefix. in the pch file (or directly put it in-Prefix. in pch.
This article is organized from http://www.cocoachina.com/applenews/devnews/2013/0328/5907.html.
You can add, delete, or modify these macros based on your habits.
//// MacroDefinition. h // MacroDefinitionDemo /// Created by wind on 13-6-9. // Copyright (c) 2013. all rights reserved. // # ifndef MacroDefinition_h # define MacroDefinition_h // specify the device size. // NavBar height # define NavigationBar_HEIGHT 44 // obtain the screen width and height # define SCREEN_WIDTH ([UIScreen mainScreen]. bounds. size. width) # define SCREEN_HEIGHT ([UIScreen mainScreen ]. Bounds. size. height) // ------------------- get the device size ------------------------- // ------------------- print the log in DEBUG mode. The current line # ifdef DEBUG # define DLog (fmt ,...) NSLog (@ "% s [Line % d]" fmt), _ PRETTY_FUNCTION __, _ LINE __, ##__ VA_ARGS __); # else # define DLog (...) # endif // rewrite NSLog. Print the log and current number of lines in Debug mode # if DEBUG # define NSLog (FORMAT ,...) fprintf (stderr, "\ nfunction: % s line: % d content: % s \ n ",_ _ FUNCTION __, _ LINE __, [[NSString stringWithFormat: FORMAT, ##__va_args _] UTF8String]); # else # define NSLog (FORMAT ,...) nil # endif // print logs in DEBUG mode. A warning is displayed for the current row. # ifdef DEBUG # define ULog (fmt ,...) {UIAlertView * alert = [[UIAlertView alloc] initWithTitle: [NSString stringWithFormat: @ "% s \ n [Line % d]", _ PRETTY_FUNCTION __, _ LINE _] message: [NSString stringWithFormat: fmt, ##__va_args _] delegate: nil cance LButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show] ;}# else # define ULog (...) # endif # define ITTDEBUG # define limit 10 # define limit 3 # define limit 1 # ifndef ITTMAXLOGLEVEL # ifdef DEBUG # define ITTMAXLOGLEVEL limit # else # define ITTMAXLOGLEVEL limit # endif // general purpose logger. this ignores logging levels. # ifdef ITTDEBUG # define IT TDPRINT (xx ,...) NSLog (@ "% s (% d):" xx, _ PRETTY_FUNCTION __, _ LINE __, ##__va_args __) # else # define ITTDPRINT (xx ,...) (void) 0) # endif // Prints the current method's name. # define ITTDPRINTMETHODNAME () ITTDPRINT (@ "% s", _ PRETTY_FUNCTION _) // Log-level based logging macros. # if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL # define ITTDERROR (xx ,...) ITTDPRINT (xx, ##__ VA_ARGS _) # else # define ITTDERROR (xx ,...) (void) 0) # endif # if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL # define ITTDWARNING (xx ,...) ITTDPRINT (xx, ##__ VA_ARGS _) # else # define ITTDWARNING (xx ,...) (void) 0) # endif # if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL # define ITTDINFO (xx ,...) ITTDPRINT (xx, ##__ VA_ARGS _) # else # define ITTDINFO (xx ,...) (void) 0) # endif # ifdef ITTDEBUG # define ITTDCONDITIONLOG (condition, xx ,...) {if (condition) {\ ITTDPRINT (xx, ##__ VA_ARG S _) ;\}\} (void) 0) # else # define ITTDCONDITIONLOG (condition, xx ,...) (void) 0) # endif # define ITTAssert (condition ,...) \ do {\ if (! (Condition) {\ [NSAssertionHandler currentHandler] \ response: [NSString stringwithuf8string :__ PRETTY_FUNCTION _] \ file: [NSString stringwithuf8string :__ FILE _] \ lineNumber: __line _ \ description :__ VA_ARGS _]; \}\} while (0) // --------------------- print logs -------------------------- // ------------------------ system -------------------------- // obtain the system version # define IOS_VERSION [[UIDevice currentDevice] SystemVersion] floatValue] # define CurrentSystemVersion [[UIDevice currentDevice] systemVersion] // obtain the current language # define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex: 0]) // determine whether the Retina screen, device % fhone 5, and iPad # define isRetina ([UIScreen instancesRespondToSelector: @ selector (currentMode)]? CGSizeEqualToSize (CGSizeMake (640,960), [[UIScreen mainScreen] currentMode]. size): NO) # define iPhone5 ([UIScreen instancesRespondToSelector: @ selector (currentMode)]? CGSizeEqualToSize (CGSizeMake (640,113 6), [[UIScreen mainScreen] currentMode]. size): NO) # define isPad (UI_USER_INTERFACE_IDIOM () = UIUserInterfaceIdiomPad) // determine whether it is a real machine or a Simulator # if TARGET_ OS _IPHONE // iPhone Device # endif # if TARGET_IPHONE_SIMULATOR // iPhone Simulator # endif // check the system version # define system_version_to _to (v) ([[UIDevice currentDevice] systemVersion] compare: v options: NSNumericSearch] = NSOrderedSame) # d Efine SYSTEM_VERSION_GREATER_THAN (v) ([[UIDevice currentDevice] systemVersion] compare: v options: NSNumericSearch] = NSOrderedDescending) # define Merge (v) ([[[UIDevice currentDevice] systemVersion] compare: v options: NSNumericSearch]! = NSOrderedAscending) # define SYSTEM_VERSION_LESS_THAN (v) ([[UIDevice currentDevice] systemVersion] compare: v options: NSNumericSearch] = NSOrderedAscending) # define sequence (v) ([[[UIDevice currentDevice] systemVersion] compare: v options: NSNumericSearch]! = NSOrderedDescending) // ------------------------ system running // ------------------------ memory ---------------------------- // use ARC and do not use ARC # if _ has_feature (objc_arc) // compiling with ARC # else // compiling without ARC # endif # pragma mark-common functions # define RELEASE_SAFELY (_ POINTER) {[_ POINTER release]; _ POINTER = nil;} // release an object # define SAFE_DELETE (P) if (P) {[P release], P = nil;} # define SAFE_RELEASE (x) [x release]; x = nil // ---------------------- memory usage // ---------------------- image reading // read local images # define LOADIMAGE (file, ext) [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: file ofType: ext] // defines the UIImage object # define IMAGE (A) [UIImage imageWithContentsOfFile: [[NSBundle mainBundle] pathForResource: A ofType: nil] // define the UIImage object # define ImageNamed (_ pointer) [UIImage imageNamed: [UIUtil imageName: _ pointer] // we recommend that you use the first two macro definitions, higher performance than the latter // ------------------------ picture -------------------------------- // ---------------------- color class encoding // rgb color conversion hexadecimal> 10 hexadecimal) # define UIColorFromRGB (rgbValue) [UIColor colorWithRed :( (float) (rgbValue & 0xFF0000)> 16)/255.0 green :( (float) (rgbValue & 0xFF00)> 8 )) /255.0 blue :( (float) (rgbValue & 0xFF)/255.0 alpha: 1.0] // COLOR settings with RGBA # define COLOR (R, G, B,) [UIColor colorWithRed: R/255.0 green: G/255.0 blue: B/255.0 alpha: A] // obtain the RGB color # define RGBA (r, g, B,) [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) // background color # define BACKGROUND_COLOR [UIColor colorWithRed: 242.0/255.0 green: 236.0/255.0 blue: 231.0/255.0 alpha: 1.0] // clear the background color # define CLEARCOLOR [UIColor clearColor] # pragma mark-color functions # define RGBCOLOR (r, g, B) [UIColor colorWithRed :( r) /255.0f green :( g)/255.0f blue :( B)/255.0f alpha: 1] # define RGBACOLOR (r, g, B, a) [UIColor colorWithRed :( r) /255.0f green :( g)/255.0f blue :( B)/255.0f alpha :( a)] // ---------------------- color class ---------------------------- // ------------------------ other fonts // simplified FONT definition of 正 # define FONT (F) [UIFont fontWithName: @ "FZHTJW--GB1-0" size: f] // define an API # define APIURL @" http://xxxxx/ "// Log on to the API # define APILogin [APIURL stringByAppendingString: @" Login "] // set the tag attribute of the View # define VIEWWITHTAG (_ OBJECT, _ TAG) [_ OBJECT viewWithTag: _ TAG] // program localization, referencing International files # define MyLocal (x ,...) NSLocalizedString (x, nil) // G-C-D # define BACK (block) dispatch_async (dispatch_get_global_queue (queue, 0), block) # define MAIN (block) dispatch_async (blocks) // NSUserDefaults instantiation # define USER_DEFAULT [NSUserDefaults standardUserDefaults] // obtain the radians and radians from the angle to obtain the angle # define degreesToRadian (x) (M_PI * (x)/180.0) # define radianToDegrees (radian) (radian * 180.0)/(M_PI) // list a class # define SYNTHESIZE_SINGLETON_FOR_CLASS (classname) \ static classname * shared # classname = nil; \ + (classname *) shared # classname \ {\ @ synchronized (self) \ {\ if (shared ## classname = nil) \ {\ shared # classname = [[self alloc] init] ;\}\}\ return shared # classname ;\}\+ (id) allocWithZone :( NSZone *) zone \ {\@ synchronized (self) \ {\ if (shared # classname = nil) \ {\ shared # classname = [super allocWithZone: zone]; \ return shared # classname ;\}\\ return nil ;\}\- (id) copyWithZone :( NSZone *) zone \{\ return self; \} # endif
MacroDefinition. h: https://github.com/XFZLDXF/Macro
This article from the "fresh wind wave" blog, please be sure to keep this source http://duxinfeng.blog.51cto.com/3911492/1219766