How to know if my Xcode iPhone project is using ARC?

孤街醉人 提交于 2019-12-03 01:04:10

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.

(You can also use the search bar in Build Settings for OBJC_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]

If you get an error:

ARC forbids explicit message send of 'autorelease'

Then you're using 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

Just search for Automatic in your target's build settings:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!