Ios development-commonly used macro definition (partial conversion), ios

Source: Internet
Author: User

Ios development-commonly used macro definition (partial conversion), ios

1. When release is enabled, the log is blocked.

C code
  • # If defined (DEBUG) & DEBUG = 1
  • # Else
  • # Define NSLog (...){};
  • # Endif
  • #if defined (DEBUG) && DEBUG == 1#else#define NSLog(...) {};#endif

     

    2. Execute the block in the main thread or in the background

    C code
  • # Define BACK (block) dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
  • # Define MAIN (block) dispatch_async (dispatch_get_main_queue (), block)
  • #define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)#define MAIN(block) dispatch_async(dispatch_get_main_queue(),block)

     

    3. device-related

     

    C code
  • # 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)
  • # Define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
  • # Define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex: 0])
  • #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)#define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)#define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0]) 

     

    4. differentiate between simulators and real machines

    C code
  • # If TARGET_ OS _IPHONE
  • // IPhone Device
  • # Endif
  • # If TARGET_IPHONE_SIMULATOR
  • // IPhone Simulator
  • # Endif
  • #if TARGET_OS_IPHONE//iPhone Device#endif#if TARGET_IPHONE_SIMULATOR//iPhone Simulator#endif

     

    5. Perform different operations based on whether ARC is used

    C code
  • # If _ has_feature (objc_arc)
  • // Compiling with ARC
  • # Else
  • // Compiling without ARC
  • # Endif
  • Related Article

    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.