问题描述
我想知道我的Xcode iPhone项目是否正在使用ARC,我不记得在创建项目时是否勾选了该框。
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.
我该怎么办?获取此信息?
How can I get this information?
推荐答案
选择您的项目,然后选择构建设置。在 Apple LLVM编译器 - 语言部分中查找 Objective-C自动引用计数。确保选择目标;虽然您可以在项目中设置它,但目标可以覆盖它。
Select your project, then Build Settings. Look for Objective-C Automatic Reference Counting in the Apple LLVM Compiler - Language section. Make sure you select the target; while you can set this in the project, the target can override it.
(您还可以使用构建设置中的搜索栏 OBJC_ARC
。)
(You can also use the search bar in Build Settings for OBJC_ARC
.)
请记住,您可以在构建阶段基于每个文件打开或关闭ARC。
Keep in mind, too, that you can turn ARC on or off on a per file basis in build phases.
或者,只需在代码中尝试这样的事情:
Or, just try something like this in code:
[[[NSObject alloc] init] autorelease]
如果您收到错误:
ARC forbids explicit message send of 'autorelease'
然后你正在使用ARC。
Then you're using ARC.
您还可以通过检查来源源代码文件中的ARC:
You can also require ARC from a source code file by checking for it:
#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
这篇关于如何知道我的Xcode iPhone项目是否使用ARC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!