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 ([[[ uidevice currentdevice].systemversion Doublevalue] >= 7.0])
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 Kmainscreenheight ([UIScreen mainscreen].applicationframe.size.height)
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 # define SINGLETON_INTERFACE (ClassName) + (ClassName *) shared# #className;//@implementation # define Singleton_implementation (className) static className *_instance; + (ID) allocwithzone: (struct _nszone *) zone { static dispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{ _instance = [Super Allocwithzone:zone]; }); return _instance; } + (ClassName *) shared# #className { static dispatch_once_t Oncetoken; Dispatch_once (&oncetoken, ^{ _instance = [[Self alloc] init]; }); return _instance; }