zoukankan      html  css  js  c++  java
  • ios开发--常用宏定义(部分转)

    1、release时,屏蔽log

    C代码 复制代码 收藏代码
    1. #if defined (DEBUG) && DEBUG == 1  
    2.   
    3. #else  
    4. #define NSLog(...) {};  
    5. #endif  
    #if defined (DEBUG) && DEBUG == 1
    
    #else
    #define NSLog(...) {};
    #endif

    2、在主线程或在后台执行block

    C代码 复制代码 收藏代码
    1. #define BACK(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)  
    2. #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、设备相关

    C代码 复制代码 收藏代码
    1. #define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)  
    2.   
    3. #define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)  
    4.   
    5. #define isPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)  
    6.   
    7. #define CurrentSystemVersion ([[UIDevice currentDevice] systemVersion])  
    8.   
    9. #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、区分模拟器和真机

    C代码 复制代码 收藏代码
    1. #if TARGET_OS_IPHONE  
    2. //iPhone Device  
    3. #endif  
    4.   
    5. #if TARGET_IPHONE_SIMULATOR  
    6. //iPhone Simulator  
    7. #endif  
    #if TARGET_OS_IPHONE
    //iPhone Device
    #endif
    
    #if TARGET_IPHONE_SIMULATOR
    //iPhone Simulator
    #endif

    5、根据是否使用ARC做不同操作

    C代码 复制代码 收藏代码
    1. #if __has_feature(objc_arc)  
    2.     //compiling with ARC  
    3. #else  
    4.     // compiling without ARC  
    5. #endif  
  • 相关阅读:
    Thrift全面介绍
    ZooKeeper全面介绍
    Redis全面介绍
    第三篇:彻底解决ssh.invoke_shell() 返回的中文问题
    第二篇:ssh.invoke_shell() 切换root出现的新问题
    第一篇:UnicodeDecodeError: 'utf-8' codec can't decode byte 0xc3 in position 0: invalid continuation byte
    pycharm安装 suds模块报错:AttributeError: module 'pip' has no attribute 'main'
    变量赋值理解--Pyton中让两个值互换的方法
    02 Django框架基础(APP的创建访问)
    01 Web框架介绍
  • 原文地址:https://www.cnblogs.com/lovewx/p/4380833.html
Copyright © 2011-2022 走看看