IOS-Xcode中 Object-C中编译ARC配置

Xcode4.2(iOS 5)以后启用了ARC(Automatic Reference Countion)技术(即内存自动管理机制)

1、需要iOS5才支持;

2、很多引用的类库暂时还不支持麻烦的是对大多数第三方库需要加禁用arc的编译flag因为大多都因为兼容性还在使用手动内存管理。

虽然4.2以后版本仍然可以不开启ARC,  但是我们在建工程的时候有时为了不想管理内存然后就启用了ARC,

但是再开发过程中需要用到第三开发类库,

而这些第三方类库或是没做更新而不支持ARC,然后编译时就出现下列错误:

'release' is unavailable: not available in automatic reference counting mode

ARC forbids explicit message send of 'release'

'autorelease' is unavailable: not available in automatic reference counting mode

ARC forbids explicit message send of 'autorelease'

'retain' is unavailable: not available in automatic reference counting mode

ARC forbids explicit message send of 'retain'

 

(1)对单个文件取消ARC的解决办法:

1.在targets->build phases中修改compiler Flags属性,添加:-fobjc-arc,就可以让旧的工程支持arc;

2.在targets->build phases中修改compiler Flags属性,添加:-fno-objc-arc,就可以让原来支持arc的工程不使用arc,对于大部分第三方类库来说都可以顺利编译通过

 

(2)对整个工程取消ARC的解决办法:

打开你的工程,点击目录的工程文件,最顶端蓝色的,

然后选择project下你的工程,还是蓝色那项,然后build Settings,然后往下拉,在Apple LLVM 5.0 - Language - Objective C 里有一个选项,Objective-C Automatic Reference Counting 选择NO,就可以了。

project -> 

build Settings -> 

Apple LLVM 5.0 - Language - Objective C ->

Objective-C Automatic Reference Counting 

 

posted on 2014-07-10 16:05  小魔一剑  阅读(696)  评论(0编辑  收藏  举报