在Xcode中部分禁用ARC

大家都清楚ARC(Automatic Reference Counting)是Xcode中很有用的新特色,
ARC会自动检查对象计数,从而在引用数为0时释放对象,让大家的工作轻松了很多
ARC工作在编译阶段,而不是运行阶段

ARC让代码中很多的retain和release变成了不再必要,简化了程序书写
但很多第三方库中,会自行控制对象的释放,经常会有
@property (nonatomic, readwrite, assign) __weak

在ARC工程中引用非ARC的库,会出现下面的编译错误
property attributes ‘assign’ and ‘weak’ are mutually exclusive

这时,只需要修改引用到非ARC库的源码编译参数就可以了
target -> Build Phases -> Compile Sources -> 相应.m文件
增加编译参数 -fno-objc-arc 就好啦

为了简化工作,把interface中使用到第三方库的部分放到.m文件中,或直接用反射,会简化整个过程

另外,如果你发下使用非ARC库时,出现对象不能retain的状况,试试在link时,加上参数

-all_load
-ObjC

Leave a Reply

Your email address will not be published. Required fields are marked *

*