zoukankan      html  css  js  c++  java
  • Making ARC and non-ARC files play nice together

    From Codeography


    If you want to exclude a file from being compiled with ARC you can do so by setting a flag on the .m file:

    Click the Project -> Build Phases Tab -> Compile Sources Section -> Double Click on the file name

    Then add -fno-objc-arc to the popup window.

    Likewise, if you want to include a file in ARC, you can use the -fobjc-arc flag.

    Xcode Screen Shot

    See the clang docs for more details.

    A helpful trick is to use the __has_feature language extension to throw errors when this is not set properly.

    Enforce a file is ARC:

    #if ! __has_feature(objc_arc)
    #error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag
    #endif
    

    The inverse:

    #if __has_feature(objc_arc)
    #error This file cannot be compiled with ARC. Either turn off ARC for the project or use -fno-objc-arc flag
    #endif
    

    This was adapted from a post by Greg Parker on the on the Objective-C mailing list. He goes on to point out the following:

    You should be careful with the interface to your shared code such that ARC and non-ARC clients can use it freely. * Conform to Cocoa's memory management conventions even though an all-ARC or no-ARC project would not require it * Don't use object pointers inside C structs * Avoid CF types

  • 相关阅读:
    nginx正则配置解释和fastadmin
    Centos7中systemctl命令详解
    layer的iframe层的传参和回参
    centOS下jenkins
    centos下nginx安装和配置
    python文件目录练习题【一】
    python正则模块re使用案例
    python字符串常用方法
    Swoole的多进程模块
    swoole学习
  • 原文地址:https://www.cnblogs.com/ihojin/p/arc-and-non-arc.html
Copyright © 2011-2022 走看看