Macro definitions commonly used in IOS development

Source: Internet
Author: User

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; }




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.