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

  • 相关阅读:
    有趣的放大镜
    特效代码
    向数据库添加学生信息。存放在REQUEST对象里
    机房servlet过滤器
    冒泡排序法
    验证码 随机生成器 详解
    生成器 种子
    生日
    在字符串里寻找某字符出现的个数
    课堂随笔
  • 原文地址:https://www.cnblogs.com/ihojin/p/arc-and-non-arc.html
Copyright © 2011-2022 走看看