明确启用ARC的实用工具? [英] Pragma to explicitly enable ARC?

查看:134
本文介绍了明确启用ARC的实用工具?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Objective-C(或Objective-C ++)源文件中是否存在#pragma(或其他某种构造)以显式启用自动引用计数(ARC)?如果源文件在未启用ARC的情况下导致编译失败,那就更好了.

Is there a #pragma (or otherwise some construct) to explicitly enable automatic reference counting (ARC) in an Objective-C (or Objective-C++) source file? Even better if the source file can cause compilation to fail if ARC is not enabled.

我开始拥有许多可以与其他项目共享的纯ARC源文件.其中大多数包含用于扩展内置类的类别方法.我只是不想将它们意外地包含在非ARC项目中,并开始泄漏内存.

I'm starting to have a number of ARC-only source files that can be potentially shared with other projects. Most of these contain category methods to extend built-in classes. I just don't want to accidentally include these in a non-ARC project and starts leaking out memory.

提前谢谢!

推荐答案

据我所知,没有办法明确启用或禁用ARC.

As far as I can tell there is no way to explicitly enable or disable ARC.

但是可以检测是否已启用.只需将以下代码段添加到任何需要ARC的文件中即可.

However it is possible to detect if it is enabled. Simply add the following snippet to any file that requires ARC.

#ifndef __has_feature
  #define __has_feature(x) 0 /* for non-clang compilers */
#endif

#if !__has_feature(objc_arc)
  #error ARC must be enabled!
#endif

更多信息:
http://clang.llvm.org/docs/AutomaticReferenceCounting.html
http://clang.llvm.org/docs/LanguageExtensions.html#__has_feature_extension

More info:
http://clang.llvm.org/docs/AutomaticReferenceCounting.html
http://clang.llvm.org/docs/LanguageExtensions.html#__has_feature_extension

这篇关于明确启用ARC的实用工具?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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