我怎么知道我的程序是否启用了ARC? [英] How do I know if my program has ARC enabled or not?

查看:187
本文介绍了我怎么知道我的程序是否启用了ARC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Xcode项目向导创建了一个支持ARC的项目。与没有ARC支持的程序相比,我没有发现任何差异。是否有任何提示可以告诉我我的程序是否支持ARC?

I create a project with ARC support using the Xcode project wizard. Compared with a program without ARC support, I did not notice any differences. Is there any hint that can tell me if my program supports ARC?

我正在使用XCode 4.2.1 Build 4D502

I am using XCode 4.2.1 Build 4D502

推荐答案

您可以使用 __ has_feature ,也许可以在控制台中记录项目是否包含ARC,如下所示:

You can use __has_feature, maybe logging whether the project has ARC in the console like this:

#if __has_feature(objc_arc)
    // ARC is On
    NSLog(@"ARC on");

#else
    // ARC is Off
    NSLog(@"ARC off");

#endif

或者,不仅记录ARC是否开启,如果ARC打开(或关闭),请尝试使编译器引发错误:

Alternatively, instead of just logging whether ARC is on, try making the compiler raise an error if ARC is on (or off) like this:

#if  ! __has_feature(objc_arc)
    #error This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
#endif

这篇关于我怎么知道我的程序是否启用了ARC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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