如何知道我的 Xcode iPhone 项目是否使用 ARC?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10508228/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to know if my Xcode iPhone project is using ARC?
提问by Steven Fisher
I want to know if my Xcode iPhone project is using ARC, and I can't remember if I ticked that box when creating the project.
我想知道我的 Xcode iPhone 项目是否正在使用 ARC,我不记得我在创建项目时是否勾选了那个框。
How can I get this information?
我怎样才能得到这些信息?
回答by Steven Fisher
Select your project, then Build Settings. Look for Objective-C Automatic Reference Countingin the Apple LLVM Compiler - Languagesection. Make sure you select the target; while you can set this in the project, the target can override it.
选择您的项目,然后选择Build Settings。在Apple LLVM 编译器 - 语言部分查找Objective-C 自动引用计数。确保你选择了目标;虽然您可以在项目中设置它,但目标可以覆盖它。
(You can also use the search bar in Build Settings for OBJC_ARC
.)
(您也可以使用 Build Settings 中的搜索栏OBJC_ARC
。)
Keep in mind, too, that you can turn ARC on or off on a per file basis in build phases.
还要记住,您可以在构建阶段基于每个文件打开或关闭 ARC。
Or, just try something like this in code:
或者,在代码中尝试这样的事情:
[[[NSObject alloc] init] autorelease]
If you get an error:
如果出现错误:
ARC forbids explicit message send of 'autorelease'
Then you're using ARC.
那么你正在使用ARC。
You can also require ARC from a source code file by checking for it:
您还可以通过检查源代码文件中的 ARC 来要求它:
#if !__has_feature(objc_arc)
#error This file must be built with ARC.
// You can turn on ARC for only this file by adding -fobjc-arc to the build phase.
#endif
回答by Ashley Mills
Just search for Automaticin your target's build settings:
只需在目标的构建设置中搜索Automatic: