是否可以在不添加"fno-objc-arc"的情况下启用非弧形文件?在编译阶段的源代码中? [英] Is it possible to enable non-arc files without adding "fno-objc-arc" in compile sources of Build Phases?

查看:117
本文介绍了是否可以在不添加"fno-objc-arc"的情况下启用非弧形文件?在编译阶段的源代码中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以以某种方式处理非弧形文件而无需在构建阶段将fno-objc-arc添加到编译源中?更具体地说,是否有任何方法可以在代码中的某处添加fno-objc-arc?原因是,我想开放使用非弧形文件的我的一个库的源代码,并且我不希望使用我的库的人手动添加fno-objc-arc.只需拖放...

Is it possible to somehow handle the non-arc files without adding fno-objc-arc to the compile sources in the build phases? More specifically, is there any way to add fno-objc-arc somewhere in the code? The reason is, I want to open source one of my library which uses non-arc files and I don't want people who use my library to manually add fno-objc-arc. Just drag and drop...

推荐答案

否.但是,如果您查看某些库的功能,它们会编写宏,这些宏将有条件地调用MRC调用,例如releaseautorelease等,具体取决于用户是否使用ARC进行编译,例如使用__has_feature(objc_arc)测试.然后,代码使用这些宏,而不是标准的releaseretainautorelease调用.经过精心实施,您便可以拥有一个同时支持ARC和MRC的代码库.

No. But if you look at what some libraries do, they write macros that will conditionally call the MRC calls, e.g., release, autorelease, etc., depending upon whether the user is compiling with ARC or not, e.g. using the __has_feature(objc_arc) test. The code then uses these macros, rather than the standard release, retain, autorelease calls. With careful implementation, you can then have a single codebase support both ARC and MRC.

例如,查看 FMDatabase.h FMDB库.实际上,您可以使用这些宏替换您的MRC调用,并且仅在有条件的情况下包含它们,具体取决于项目是否使用ARC.

For example, look at FMDatabase.h of the FMDB library. Effectively, you replace your MRC calls with these macros, and they'll only be conditionally included, depending upon whether the project is using ARC or not.

#if ! __has_feature(objc_arc)
    #define FMDBAutorelease(__v) ([__v autorelease]);
    #define FMDBReturnAutoreleased FMDBAutorelease

    #define FMDBRetain(__v) ([__v retain]);
    #define FMDBReturnRetained FMDBRetain

    #define FMDBRelease(__v) ([__v release]);
#else
    // -fobjc-arc
    #define FMDBAutorelease(__v)
    #define FMDBReturnAutoreleased(__v) (__v)

    #define FMDBRetain(__v)
    #define FMDBReturnRetained(__v) (__v)

    #define FMDBRelease(__v)
#endif

这篇关于是否可以在不添加"fno-objc-arc"的情况下启用非弧形文件?在编译阶段的源代码中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆