Sometimes, we need to make the code simple so that it's easy to read code. We can extract some unchanging stuff and change things as parameters. Defined as a macro, so it's much easier to write.
The following examples illustrate some common macro definitions and share them with you:
1. Determine if the device's operating system is IOS7
#define IOS7 (
2. Determine if the current device is IPhone5
#define KScreenIphone5 ([[[UIScreen Mainscreen] bounds].size.height) >=568)
3. Get the height of the current screen
#define
4. Get the width of the current screen
#define kmainscreenwidth ([UIScreen mainscreen].applicationframe.size.width)
5. Get RGB color
#define Smscolor (R, G, b) [Uicolor colorwithred: (r)/255.0 Green: (g)/255.0 Blue: (b)/255.0 alpha:1.0]
6: Custom Log
#ifdef DEBUG #define Smslog (...) NSLog (__va_args__)#else#define smslog (...) #endif
7. Single case
//@interface#defineSingleton_interface (ClassName) + (ClassName *) shared# #className;//@implementation#defineSingleton_implementation (ClassName)StaticClassName *_instance;+ (ID) Allocwithzone: (struct_nszone *) Zone {Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{_instance=[Super Allocwithzone:zone]; }); return_instance;} + (ClassName *) shared# #className {Staticdispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{_instance=[[Self alloc] init]; }); return_instance;}