针对项目中部分文件开启或者关闭ARC

Making ARC and non-ARC files play nice together

If you want to exclude a file from being compiled with ARC you can do so by setting a flag on the .m file:

Click the Project -> Build Phases Tab -> Compile Sources Section -> Double Click on the file name

Then add -fno-objc-arc to the popup window.

Likewise, if you want to include a file in ARC, you can use the -fobjc-arc flag.

Xcode Screen Shot

See the clang docs for more details.

A helpful trick is to use the __has_feature language extension to throw errors when this is not set properly.

Enforce a file is ARC:

#if ! __has_feature(objc_arc)
#error This file must be compiled with ARC. Either turn on ARC for the project or use -fobjc-arc flag
#endif

The inverse:

#if __has_feature(objc_arc)
#error This file cannot be compiled with ARC. Either turn off ARC for the project or use -fno-objc-arc flag
#endif

This was adapted from a post by Greg Parker on the on the Objective-C mailing list. He goes on to point out the following:

You should be careful with the interface to your shared code such that ARC and non-ARC clients can use it freely. * Conform to Cocoa's memory management conventions even though an all-ARC or no-ARC project would not require it * Don't use object pointers inside C structs * Avoid CF types

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值