zoukankan      html  css  js  c++  java
  • 兼容arc和非arc的处理方法

    查看原文:http://www.heyuan110.com/archives/614
    1.如果是使用第三方的模块简单处理就是

    选择你编译的的target,build phases-->Compiled sources中,双击没用arc的文件,写-fno-objc-arc

    相应的,没开启ARC的工程单独为某文件开启arc,compile flag填 -fobjc-arc

    2.如果写一个需要兼容arc,非arc,gc等模块的时候我们可以使用预处理来判断一下

    #if(!__has_feature(objc_arc))
    [_someObj release];
    #endif
    也可以在你全局的pch中加入这个宏

    #ifndef OBJC_ARC_ENABLED
    #ifdef __has_feature
    #define OBJC_ARC_ENABLED __has_feature(objc_arc)
    #else
    #define OBJC_ARC_ENABLED 0
    #endif
    #endif
    以后判断就

    #if(OBJC_ARC_ENABLED)
    [_someObj release];
    #endif

    【附】下面给出一个完整的宏定义判断列表

    #if !defined(__clang__) || __clang_major__ < 3
    #ifndef __bridge
    #define __bridge
    #endif

    #ifndef __bridge_retain
    #define __bridge_retain
    #endif

    #ifndef __bridge_retained
    #define __bridge_retained
    #endif

    #ifndef __autoreleasing
    #define __autoreleasing
    #endif

    #ifndef __strong
    #define __strong
    #endif

    #ifndef __unsafe_unretained
    #define __unsafe_unretained
    #endif

    #ifndef __weak
    #define __weak
    #endif
    #endif

    //如果
    #if __has_feature(objc_arc)
    #define SAFE_ARC_PROP_RETAIN strong
    #define SAFE_ARC_RETAIN(x) (x)
    #define SAFE_ARC_RELEASE(x)
    #define SAFE_ARC_AUTORELEASE(x) (x)
    #define SAFE_ARC_BLOCK_COPY(x) (x)
    #define SAFE_ARC_BLOCK_RELEASE(x)
    #define SAFE_ARC_SUPER_DEALLOC()
    #define SAFE_ARC_AUTORELEASE_POOL_START() @autoreleasepool {
    #define SAFE_ARC_AUTORELEASE_POOL_END() }
    #else
    #define SAFE_ARC_PROP_RETAIN retain
    #define SAFE_ARC_RETAIN(x) ([(x) retain])
    #define SAFE_ARC_RELEASE(x) ([(x) release])
    #define SAFE_ARC_AUTORELEASE(x) ([(x) autorelease])
    #define SAFE_ARC_BLOCK_COPY(x) (Block_copy(x))
    #define SAFE_ARC_BLOCK_RELEASE(x) (Block_release(x))
    #define SAFE_ARC_SUPER_DEALLOC() ([super dealloc])
    #define SAFE_ARC_AUTORELEASE_POOL_START() NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    #define SAFE_ARC_AUTORELEASE_POOL_END() [pool release];
    #endif

  • 相关阅读:
    JavaScript创建块级作用域
    JavaScript数组求最大值 面试题
    JavaScript类数组转换为数组 面试题
    JavaScript实现深拷贝(深复制) 面试题
    javascript洗牌算法 乱序算法 面试题
    3GPP 测试 /etc/udev/ruse.d/50文件 /lib/udev/ruse.d/55* 网络配置
    【网络】TCP/IP连接三次握手
    SVN 使用方法
    Git 使用方法
    LoadRunner性能测试工具
  • 原文地址:https://www.cnblogs.com/ligun123/p/2956180.html
Copyright © 2011-2022 走看看